I provide a Matplotlib Figure with one or more time-vector and XY subplots of Numpy vectors.

Construct an instance of me with the total number of subplots (to be intelligently apportioned into one or more rows and columns) or, with two constructor arguments, the number of columns followed by the number of rows.

With the filePath keyword, you can specify the file path of a PNG file for me to create or overwrite with each call to show.

You can set the width and height of the Figure with constructor keywords, and (read-only) access them via my properties of the same names. Or set my figSize attribute (in a subclass or with that constructor keyword) to a 2-sequence with figure width and height. The default width and height is just shy of the entire monitor size.

The dimensions are in inches, converted to pixels at 100 DPI, unless they are both integers and either of them exceeds 75 (which would equate to a huge 7,500 pixels). In that case, they are considered to specify the pixel dimensions directly.

Use the "Agg" backend by supplying the constructor keyword useAgg. This works better for plotting to an image file, and is selected automatically if you supply a filePath to the constructor. Be aware that, once selected, that backend will be used for all instances of me. If you're using the "Agg" backend, you should specify it the first time an instance is constructed.

Setting the verbose keyword True puts out a bit of info about annotator positioning. Not for regular use.

Any other keywords you supply to the constructor are supplied to the underlying Matplotlib plotting call for all subplots.

Keep the API for OptsBase handy, and maybe a copy of the source, to see all the plotting options you can set.

Instance Variable dims A dict of sub-dicts of the dimensions of various text objects, keyed first by subplot index then the object name.
Class Method setup Called by each instance of me during instantiation. Sets a class-wide Matplotlib pyplot import the first time it's called.
Class Method showAll Calls show for the figures generated by all instances of me.
Method __init__ Plotter(N, *args, **kw)
Method __del__ Safely ensures that I am removed from the class-wide ph instance of PlotterHolder.
Method subplots_adjust Adjusts spacings.
Method width Figure width (inches).
Method height Figure height (inches).
Method __nonzero__ I evaluate as True if I have any subplots defined yet.
Method __getattr__ You can access plotting methods and a given subplot's plotting options as attributes.
Method __enter__ Upon an outer context entry, sets up the first subplot with cleared axes, preserves a copy of my global options, and returns a reference to myself as a subplotting tool.
Method __exit__ Upon completion of context, turns minor ticks and grid on if enabled for this subplot's axis, and restores global (all subplots) options.
Method show Call this to show the figure with suplots after the last call to my instance.
Method clear Clears my figure with all annotators and artist dimensions. Removes my ID from the class-wide PlotterHolder.
Method xBounds See Subplotter.xBounds.
Method yBounds See Subplotter.yBounds.
Method fontsize Undocumented
Method doKeywords Applies line style/marker/color settings as keywords for this vector, except for options already set with keywords.
Method doSettings Does set_XXX calls on the Axes object for the subplot at index k.
Method __call__ In the next (perhaps first) subplot, plots the second supplied vector (and any further ones) versus the first.
Method _maybePixels Considers the supplied figSize to be in pixels if both its elements are integers and at least one of them exceeds 75. In that case, scales it down by DPI.
Method _doPlots This gets called by __call__ at the beginning of each call to my subplot-context instance, and by __exit__ when subplot context ends, to do all the plotting for the previous subplot.

Inherited from OptsBase:

Method set Before this subplot is drawn, do a set_name=value command to the axes. You can call this method as many times as you like with a different attribute name and value.
Method prevOpts Lets you use my previous local options (or the current ones, if there are no previous ones) inside a context call.
Method add_annotation Adds the text supplied after index k at an annotation of the plotted vector.
Method add_axvline Adds a vertical dashed line at the data point with integer index k.
Method add_color Appends the supplied line style character to the list of colors being used.
Method add_legend Adds the supplied format-substituted text to the list of legend entries.
Method add_line Appends the supplied line style string(s) to my list of line styles being used.
Method add_lines Alias for add_line.
Method add_marker Appends the supplied marker style character to the list of markers being used.
Method add_plotKeyword Add a keyword to the underlying Matplotlib plotting call.
Method add_textBox Adds a text box to the specified quadrant of the subplot.
Method clear_annotations Clears the list of annotations.
Method clear_legend Clears the list of legend entries.
Method clear_plotKeywords Clears all keywords for this subplot.
Method clear_textBoxes Clears the dict of text boxes.
Method plot Specifies a non-logarithmic regular plot, unless called with the name of a different plot type.
Method plot_bar Specifies a bar plot, unless called with False.
Method plot_error Specifies an error bar plot, unless called with False.
Method plot_loglog Makes both axes logarithmic, unless called with False.
Method plot_semilogx Makes x-axis logarithmic, unless called with False.
Method plot_semilogy Makes y-axis logarithmic, unless called with False.
Method plot_stem Specifies a stem plot, unless called with False.
Method plot_step Specifies a step plot, unless called with False.
Method set_axisExact Forces the limits of the named axis ("x" or "y") to exactly the data range, unless called with False.
Method set_axvline Adds a vertical dashed line at the data point with integer index k.
Method set_colors Sets the list of colors. Call with no args to clear the list and revert to default color scheme.
Method set_firstVectorTop Has the first dependent vector (the second argument to the Plotter object call) determine the top (maximum) of the displayed plot boundary.
Method set_fontsize Sets the fontsize of the specified artist name.
Method set_grid Adds a grid, unless called with False.
Method set_legend Sets the list of legend entries.
Method set_minorTicks Enables minor ticks for axisName ("x" or "y").
Method set_tickSpacing Sets the major tick spacing for axisName ("x" or "y"), and minor tick spacing as well.
Method set_timex Uses intelligent time scaling for the x-axis, unless called with False.
Method set_title Sets a title for all subplots (if called out of context) or for just the present subplot (if called in context).
Method set_useLabels Has annotation labels point to each plot line instead of a legend, with text taken from the legend list.
Method set_xlabel Sets the x-axis label.
Method set_ylabel Sets the y-axis label.
Method set_zeroBottom Sets the bottom (minimum) of the Y-axis range to zero, unless called with False.
Method set_zeroLine Adds a horizontal line at the specified y value (default is y=0) if the Y-axis range includes that value.
Method use_bump Bumps up the common y-axis upper limit to 120% of what Matplotlib decides. Call with False to disable the bump.
Method use_grid Adds a grid, unless called with False.
Method use_legend Has an automatic legend entry added for each plot line, unless called with False.
Method use_labels Has annotation labels point to each plot line instead of a legend, with text taken from the legend list. (Works best in interactive apps.)
Method use_timex Uses intelligent time scaling for the x-axis, unless called with False.
Method _axisOpt Undocumented
dims =
A dict of sub-dicts of the dimensions of various text objects, keyed first by subplot index then the object name.
@classmethod
def setup(cls, useAgg=False):

Called by each instance of me during instantiation. Sets a class-wide Matplotlib pyplot import the first time it's called.

@classmethod
def showAll(cls):

Calls show for the figures generated by all instances of me.

def __init__(self, N, *args, **kw):

Plotter(N, *args, **kw)

def __del__(self):

Safely ensures that I am removed from the class-wide ph instance of PlotterHolder.

def _maybePixels(self, figSize):

Considers the supplied figSize to be in pixels if both its elements are integers and at least one of them exceeds 75. In that case, scales it down by DPI.

Returns the figSize in inches.

def subplots_adjust(self, *args):

Adjusts spacings.

@property
def width(self):

Figure width (inches).

@property
def height(self):

Figure height (inches).

def __nonzero__(self):

I evaluate as True if I have any subplots defined yet.

def __getattr__(self, name):

You can access plotting methods and a given subplot's plotting options as attributes.

If you request a plotting method, you'll get an instance of me with my _plotter method set to name first.

def __enter__(self):

Upon an outer context entry, sets up the first subplot with cleared axes, preserves a copy of my global options, and returns a reference to myself as a subplotting tool.

def __exit__(self, exc_type, exc_val, exc_tb):

Upon completion of context, turns minor ticks and grid on if enabled for this subplot's axis, and restores global (all subplots) options.

See:_doPlots.
def _doPlots(self):

This gets called by __call__ at the beginning of each call to my subplot-context instance, and by __exit__ when subplot context ends, to do all the plotting for the previous subplot.

Adds minor ticks and a grid, depending on the subplot-specific options. Then calls Opts.newLocal on my opts to create a new set of local options.

def show(self, windowTitle=None, fh=None, filePath=None, noShow=False):

Call this to show the figure with suplots after the last call to my instance.

If I have a non-None fc attribute (which must reference an instance of Qt's FigureCanvas, then the FigureCanvas is drawn instead of PyPlot doing a window show.

You can supply an open file-like object for PNG data to be written to (instead of a Matplotlib Figure being displayed) with the fh keyword. (It's up to you to close the file object.)

Or, with the filePath keyword, you can specify the file path of a PNG file for me to create or overwrite. (That overrides any filePath you set in the constructor.)

def clear(self):

Clears my figure with all annotators and artist dimensions. Removes my ID from the class-wide PlotterHolder.

def xBounds(self, *args, **kw):
def yBounds(self, *args, **kw):
def fontsize(self, name, default=None):
Undocumented
def doKeywords(self, kVector, kw):

Applies line style/marker/color settings as keywords for this vector, except for options already set with keywords.

Then applies plot keywords set via the set_plotKeyword call and then, with higher priority, those set via the constructor, if they don't conflict with explicitly set keywords to this call which takes highest priority.

Returns the new kw dict.

def doSettings(self, k):

Does set_XXX calls on the Axes object for the subplot at index k.

def __call__(self, *args, **kw):

In the next (perhaps first) subplot, plots the second supplied vector (and any further ones) versus the first.

If you supply a container object that houses vectors and provides access to them as items as the first argument, you can supply vector names instead of the vectors themselves. The container object must evaluate b in a as True if it contains a vector with b, and must return the vector with a[b].

Many options can be set via the methods in OptsBase, including a title, a list of plot markers and linestyles, and a list of legend entries for the plots with those keywords.

Set useLabels to True to have annotation labels pointing to each plot line instead of a legend, with text taken from the legend list.

You can override my default plotter by specifying the name of another one with the plotter keyword, e.g., plotter="step". But the usual way to do that is to call the corresponding method of my instance, e.g., sp.step(X, Y).

Any other keywords you supply to this call are supplied to the underlying Matplotlib plotting call. (NOTE: This is a change from previous versions of Yampex where keywords to this method were used to set_X the axes, e.g., ylabel="foo" results in a set_ylabel("foo") command to the axes object, for this subplot only. Use the new OptsBase.set command instead.)

Returns a SpecialAx wrapper object for the Axes object created for the plot.

If you want to do everything with the next subplot on your own, bit by bit, and only want a reference to its Axes object (still with special treatment via SpecialAx) just call this with no args.

For low-level Matplotlib operations, you can access the underlying Axes object via the returned SpecialAx object's ax attribute. But none of its special features will apply to what you do that way.

See:_doPlots.