def plot(self, *args, **kwargs): """ Translates arguments and keywords to matplotlib.axes.Axes.plot() method so they can be passed to pg.PlotItem.plot() instead. See https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.axes.Axes.plot.html :param args: Plot arguments They will be passed straight through to plot() :param kwargs: Plot keywords They will be translated from mpl to pg conventions and then passed to plot() :return: plotItem instance returned by pg.PlotItem.plot() """ need_cycle = any( [k not in kwargs.keys() for k in self.prop_cycle.keys]) if need_cycle: printd('keys needed', list(self.prop_cycle.keys), level=2) cur = self.cyc for k in self.prop_cycle.keys: if k not in kwargs.keys(): kwargs[str(k)] = cur[self.prop_cycle_index][k] printd('kwargs["{}"] = {}'.format(k, kwargs[str(k)]), level=2) self.prop_cycle_index += 1 if self.prop_cycle_index > len(self.prop_cycle): self.prop_cycle_index = 0 return super(Axes, self).plot(*args, **plotkw_translator(**kwargs))
def _process_errorbar_keywords(self, **kwargs): """Separate keywords affecting error bars from those affecting nominal values & translate to pyqtgraph""" ekwargs = copy.deepcopy(kwargs) if kwargs.get('ecolor', None) is not None: ekwargs['color'] = kwargs.pop('ecolor') if kwargs.get('elinewidth', None) is not None: ekwargs['linewidth'] = kwargs.pop('elinewidth') epgkw = plotkw_translator(**ekwargs) return epgkw
def scatter(self, x=None, y=None, **kwargs): """ Translates arguments and keywords for matplotlib.axes.Axes.scatter() method so they can be passed to pyqtgraph. https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.axes.Axes.scatter.html :param x: array-like Values for the X-axis, with length n :param y: array-like Values for the Y-axis, with length n :param s: array-like or scalar [optional] Size or sizes for the markers. If iterable, must have length n. :param c: color, sequence, or sequence of color [optional] Colors for the markers. If specifying more than one color, there must be n colors. :param marker: string [optional] Code for marker symbol, like 'o' :param cmap: string [optional] Matplotlib colormap name :param norm: Normalize class instance [optional] An instance of one of Matplotlib's normalization classes, like mpl.colors.Normalize If not provided, a new instance of mpl.colors.Normalize will be created. :param vmin: numeric scalar [optional] Minimum value for color axis. Used to initialize mpl.colors.Normalize, if needed. Otherwise, ignored. :param vmax: numeric scalar [optional] Maximum value for color axis. Used to initialize mpl.colors.Normalize, if needed. Otherwise, ignored. :param alpha: numeric scalar [optional] Opacity, between 0 (invisible) and 1 (fully opaque) :param linewidths: numeric scalar or array-like [optional] If array-like, must match length n :param verts: sequence of (x, y) [optional] Used for creating custom symbols. Set marker=None to use this. :param edgecolors: color specification or sequence of color specifications Colors for edges :param data: dict, optional Alternative way to specify some keywords. Must contain x and y. Can also contain s, c, edgecolors, and linewidths, which will override any duplicates passed in directly. :return: plotItem instance created by plot() """ x, y, kwargs = self._interpret_xy_scatter_data(x, y, **kwargs) n = len(x) linewidths = kwargs.pop('linewidths', None) brush_colors, brush_edges = self._prep_scatter_colors(n, **kwargs) for popit in [ 'cmap', 'norm', 'vmin', 'vmax', 'alpha', 'edgecolors', 'c' ]: kwargs.pop( popit, None ) # Make sure all the color keywords are gone now that they've been used. # Catch & translate other keywords kwargs['markersize'] = kwargs.pop('s', 10) kwargs.setdefault('marker', 'o') plotkw = plotkw_translator(**kwargs) # Fill in keywords we already prepared plotkw['symbolPen'] = self._setup_scatter_symbol_pen( brush_edges, linewidths) plotkw['pen'] = None plotkw['symbolBrush'] = [pg.mkBrush(color=cc) for cc in brush_colors] plotkw['symbol'] = plotkw.get('symbol', None) or self._make_custom_verts( kwargs.pop('verts', None)) return super(Axes, self).plot(x=x, y=y, **plotkw)
def axvline(self, value, **kwargs): """ Direct imitation of matplotlib axvline https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.axes.Axes.axvline.html """ return self.addLine(x=value, **plotkw_translator(**kwargs))
def test_plotkw_translator(self): newk = [{}] * self.nt for i in range(self.nt): newk[i] = plotkw_translator(**self.plot_kw_tests[i])