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
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.
|Instance Variable||dims||A dict (actually, a subclass of
|Instance Variable||Nsp||The number of subplots defined thus far defined with calls to my instance.|
|Class Method||setupClass||Called by each instance of me during instantiation. Sets a class-wide Matplotlib pyplot import the first time it's called.|
|Method||__init__||Constructor possibilities (not including keywords, except Nc):|
|Static Method||parseArgs||Parse the supplied args and kw for a constructor call.|
|Method||reset||Clears everything out to start fresh.|
|Method||__del__||Safely ensures that I am removed from the class-wide ph instance
|Method||width||Figure width (inches).|
|Method||height||Figure height (inches).|
|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, restores global (all subplots) options.|
|Method||start||An alternative to the context-manager way of using me. Just call this method and a reference to myself as a subplotting tool will be returned.|
|Method||done||Call this after a call to
|Method||updateAnnotations||Updates the positions of all annotations in an already-drawn plot.|
|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
|Method||doKeywords||Applies line style/marker/color settings as keywords for this vector, except for options already set with keywords.|
|Method||__call__||In the next (perhaps first) subplot, or one whose index is specified with keyword k, 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
Inherited from OptsBase:
|Instance Variable||opts||A dict of options.|
|Method||set||Before this subplot is drawn, do a
|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. You can use negative indices, e.g., -1 for the last data point.|
|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_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 location 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
|Method||plot_error||Specifies an error bar plot, unless called with
|Method||plot_loglog||Makes both axes logarithmic, unless called with
|Method||plot_semilogx||Makes x-axis logarithmic, unless called with
|Method||plot_semilogy||Makes y-axis logarithmic, unless called with
|Method||plot_stem||Specifies a stem plot, unless called with
|Method||plot_step||Specifies a step plot, unless called with
|Method||set_axisExact||Forces the limits of the named axis ("x" or "y") to
exactly the data range, unless called with
|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
|Method||set_fontsize||Sets the fontsize of the specified artist name.|
|Method||set_legend||Sets the list of legend entries.|
|Method||set_tickSpacing||Sets the major tick spacing for axisName ("x" or "y"), and minor tick spacing as well.|
|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_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
|Method||set_zeroLine||Draws 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
|Method||use_grid||Adds a grid, unless called with
|Method||use_legend||Has an automatic legend entry added for each plot line, unless called
|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_minorTicks||Enables minor ticks for axisName ("x" or "y",
omit for both). Call with
|Method||use_timex||Uses intelligent time scaling for the x-axis, unless called with
|Method||hide_axis||Hide the x-axis and y-axis (for images).|
Dims) of sub-dicts of the dimensions of various text objects, keyed first by subplot index then the object name.
def setupClass(cls, useAgg=False):
Called by each instance of me during instantiation. Sets a class-wide Matplotlib pyplot import the first time it's called.
If any instance of me is using the Agg renderer, all instances will.
the figures generated by all instances of me.
Constructor possibilities (not including keywords, except Nc):
Plotter(Nc, Nr): Specify Nc columns and Nr
Plotter(N): Specify up to N subplots in optimal
arrangement of columns and rows.
Plotter(N, Nc=x): Specify up to N columns subplots
with x columns.
Plotter(Nc, Nr, V): Specify Nc columns and Nr
rows, with container object V.
Plotter(Nc, Nr, V): Specify up to N subplots in
optimal arrangement of columns and rows, with container object
Plotter(N, V, Nc=x): Specify up to N columns
subplots with x columns, with container object V.
|Parameters||filePath||Specify the path of a PNG file to be created instead of a plot window being opened. (Implies useAgg.)|
|figSize||Set to a 2-sequence with figure width and height if not using the default, which is just shy of your entire monitor size. Dimensions are in inches, converted to pixels at 100 DPI, unless both are integers and either exceeds 75. Then they are considered to specify the pixel dimensions directly.|
|width||Specify the figure width part of figSize.|
|height||Specify the figure height part of figSize.|
|h2||A single index, or a sequence or set containing one or more indices, of any rows (starting with 0 for the top row) that have twice the normal height. If an invalid index is included, an exception will be raised.|
|w2||A single index, or a sequence or set containing one or more indices, of any columns (starting with 0 for the left column) that have twice the normal width. If an invalid index is included, an exception will be raised.|
def parseArgs(*args, **kw):
Parse the supplied args and kw for a constructor call.
Returns a 5-tuple with a revised args list and kw dict, the number of subplots, the number of columns, and the number of rows.
Safely ensures that I am removed from the class-wide ph instance
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.
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.
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.
Upon completion of context, turns minor ticks and grid on if enabled for this subplot's axis, restores global (all subplots) options.
If the Agg rendererer is not being used (for generating PNG files), also sets a hook to adjust the subplot spacings and annotation positions upon window resizing.
The args are just placeholders for the three args that
contextmanager supplies at the end of context:
exc_type, exc_val, exc_tb. (None are useful here.)
An alternative to the context-manager way of using me. Just call this method and a reference to myself as a subplotting tool will be returned.
finished, which is the same thing as exiting my subplotting context.
Call this after a call to
start when done
plotting. This is the alternative to the context-manager way of using
Note: If you don't call this to close out a plotting session with the alternative method, the last subplot will not get drawn!
Updates the positions of all annotations in an already-drawn plot.
calls this, it will supply the annotator for its subplot.
Adds minor ticks and a grid, depending on the subplot-specific options.
my opts to create a new set of local options.
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.)
Clears my figure with all annotators and artist dimensions. Removes my
ID from the class-wide
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.
In the next (perhaps first) subplot, or one whose index is specified with keyword k, 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
True if it contains a vector with b, and
must return the vector with
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
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.,
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.,
results in a
set_ylabel("foo") command to the
axes object, for this subplot only. Use the new
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
ax attribute. But none of its special features will apply to what
you do that way.
|Parameters||k||Set this to the integer index of the subplot you want the supplied vectors plotted in if not in sequence.|