Skip to content

Commit 11904e0

Browse files
committed
better doc for yaxes/side
1 parent 163ba0a commit 11904e0

File tree

2 files changed

+110
-64
lines changed

2 files changed

+110
-64
lines changed

doc/examples.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ gives:
7272
.. image:: images/datafile_plot.png
7373
:width: 85 %
7474

75+
.. _example_leftright:
7576

7677
Using Left and Right Axes
7778
----------------------------
@@ -86,6 +87,7 @@ and gives a plot that looks like this:
8687
.. image:: images/two_axes.png
8788
:width: 85 %
8889

90+
.. _example_multiple_yaxes:
8991

9092
Using 3 and 4 Y Axes
9193
----------------------------

doc/plotpanel.rst

Lines changed: 108 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,15 @@ many additional methods to interact with the plots.
6666
Keyword parameters in ``**kws`` other than those listed above are sent to the wx.Panel.
6767

6868

69-
:class:`PlotPanel` methods
70-
=============================================
71-
72-
73-
.. method:: plot(x, y, **kws)
74-
75-
Draw a plot of the numpy arrays *x* and *y*, erasing any existing plot. The
76-
displayed curve for these data is called a *trace*. The :meth:`plot` method
77-
has many optional parameters, all using keyword/value argument. Since most
78-
of these are shared with the :meth:`oplot` method, the full set of parameters
79-
is given in :ref:`Table of Plot Arguments <plotopt_table>`
80-
81-
.. method:: oplot(x, y, **kws)
69+
:class:`PlotPanel` conventions and common arguments
70+
============================================================
8271

83-
Draw a plot of the numpy arrays *x* and *y*, overplotting any existing
84-
plot, so that both traces are visible.
72+
The :class:`PlotPanel` methods below share many conventions and use
73+
common arguments where possible. A list of common function argumets
74+
for :meth:`plot`, :meth:`oplot`, and :meth:`scatterplot is given in
75+
:ref:`Table of Plot Arguments <plotopt_table>`. Many of these
76+
arguments and terms are alsoe used in the other function methods.
8577

86-
The :meth:`oplot` method has many optional parameters, as listed in
87-
:ref:`Table of Plot Arguments <plotopt_table>`
8878

8979
.. _plotopt_table:
9080

@@ -127,9 +117,9 @@ same meaning, as indicated by the right-most column.
127117
+------------------+------------+---------+------------------------------------------------+-----+--------------+
128118
| drawstyle | string | line | style connecting points of trace | 8 | no |
129119
+------------------+------------+---------+------------------------------------------------+-----+--------------+
130-
| side | string | left | location (side) for y-axis and label | 9 | no |
120+
| side | string | None | location (side) for y-axes and label | 9 | no |
131121
+------------------+------------+---------+------------------------------------------------+-----+--------------+
132-
| yaxes | 1,2,3,4 | 1 | location (side) for y-axis and label | 9 | no |
122+
| yaxes | 1,2,3,4 | 1 | location (side) for y-axes and label | 9 | no |
133123
+------------------+------------+---------+------------------------------------------------+-----+--------------+
134124
| yaxes_tracecolor | bool | False | use trace color for multiple y-axes | 9 | no |
135125
+------------------+------------+---------+------------------------------------------------+-----+--------------+
@@ -189,16 +179,16 @@ same meaning, as indicated by the right-most column.
189179
+------------------+------------+---------+------------------------------------------------+-----+--------------+
190180

191181

192-
As a general note, the configuration for the plot (title, labels, grid
193-
displays) and for each trace (color, linewidth, ...) are preserved for a
194-
:class:`PlotPanel`. A few specific notes:
182+
As a general note, the configuration for the plot (title, labels, grid displays) and
183+
for each trace (color, linewidth, ...) are preserved for a :class:`PlotPanel`. A few
184+
specific notes:
195185

196186
1. The title, label, and grid arguments to :meth:`plot` default to ``None``, which
197187
means to use the previously used value.
198188

199-
2. The *theme* will set the color palette and make stylistic choices. Choices
200-
include 'light' (the default), 'white-background', 'dark', 'matplotlib',
201-
'seaborn', 'ggplot', 'bmh', 'fivethirtyeight', 'grayscale', 'dark_background',
189+
2. The *theme* will set the color palette and make stylistic choices. Choices include
190+
'light' (the default), 'white-background', 'dark', 'matplotlib', 'seaborn',
191+
'ggplot', 'bmh', 'fivethirtyeight', 'grayscale', 'dark_background',
202192
'tableau-colorblind10', 'seaborn-bright', 'seaborn-colorblind', 'seaborn-dark',
203193
'seaborn-darkgrid', 'seaborn-dark-palette', 'seaborn-deep', 'seaborn-notebook',
204194
'seaborn-muted', 'seaborn-pastel', 'seaborn-paper', 'seaborn-poster',
@@ -232,10 +222,10 @@ same meaning, as indicated by the right-most column.
232222
discrete values as a function of time, left-to-right, and want to show a
233223
transition to a new value as a sudden step, you want 'steps-post'.
234224

235-
9. *side* can by one of ('left', 'right', 'right2', 'right3') or *yaxes* can
236-
be one on (1, 2, 3, 4). These are exactly equivalent ways to spectify
237-
which Y axes to use. Setting *yaxes_tracecolor* will make the
238-
Y axes use the same color as the trace using that Y axes.
225+
9. *side* can by one of (``None``, 'left', 'right', 'right2', 'right3') (default=``None``)
226+
or *yaxes* can be one on (1, 2, 3, 4) (default=1, for left-hand axes). Setting
227+
*yaxes_tracecolor* will make the Y axes use the same color as the trace using that
228+
Y axes. See :ref:`sect_yaxes_side` for details.
239229

240230
10. *marker* is one of ('+', 'o', 'x', '^', 'v', '>', '<', '|', '_', 'square',
241231
'diamond', 'thin diamond', 'hexagon', 'pentagon', 'tripod 1', or 'tripod 2').
@@ -266,14 +256,92 @@ same meaning, as indicated by the right-most column.
266256
All of these values, and a few more settings controlling whether and how to display a plot legend can be
267257
configured interactively (see Plot Configuration).
268258

269-
.. method:: update_line(trace, x, y, side='left', update_limits=True, draw=False)
259+
260+
.. _sect_yaxes_side:
261+
262+
Selecting Y-axes (left- or right-hand side)
263+
=======================================================
264+
265+
While a basic use of :class:`PlotPanel` will have a single Y-axes, it
266+
is sometimes useful to plot multiple traces together that have
267+
different ranges of Y values. Using 2 Y-axes -- the left- and
268+
right-hand sides of the plot is a very common need. Sometimes 3 or
269+
even 4 Y axes sharing an X axes can be helpful, and :class:`PlotPanel`
270+
supports plots with up to 4 of these.
271+
272+
To specify which Y axes to use, we recommeded using the argument
273+
`yaxes` which can be an integer 1, 2, 3, or 4, where 1 (the default)
274+
means the left-hand side of the plot, 2 the right-hand side, and 3 and
275+
4 additional axes displaced from the right-hand side. (see
276+
:ref:`example_leftright` and :ref:`example_multiple_yaxes`). For backward
277+
compatibility (and with no intention to deprecate this), this can also
278+
be set with the argument `side`, which can be ``None`` (meaning "use
279+
the value of `yaxes`") or one of ('left', 'right', 'right2',
280+
'right3'), m (default=``None``).
281+
282+
Setting `yaxes_tracecolor` to ``True`` will make each of the Y axes
283+
use the same color as the trace using that Y axes.
284+
285+
286+
.. _sect_datetime:
287+
288+
Using date-time data with :func:`plot`
289+
===========================================
290+
291+
If the `x` values to be plotted holds date or time data, these can be handled in
292+
a few different formats. In order for the X-axis labels to be properly
293+
displayed as a string showing the date, the values must be eventually converted
294+
to a `matplotlib.dates` object, which uses a floating point number to represent
295+
the number of days since year 0, BCE. The `wxmplot` user is not expected to do
296+
this conversion.
297+
298+
The best way to specify datetime information is to use `datetime` objects
299+
from the `datetime` library. These will be automatically recognized and
300+
properly converted.
301+
302+
If the `x` data is a list or array of integers or floats and `use_dates=True` is
303+
used, the values will be interpreted as Unix timestamps (seconds since 1970),
304+
unless `dates_styles='dates'`, in which case they will be interpreted as
305+
`matplotlib.dates`.
306+
307+
Finally, it is possible to pass in a list or array of strings as `x`, and set
308+
`use_dates=True`. In this case, the `matplotlib.dates.datestr2num` function
309+
will be used convert the string. Of course, whether this actually works well
310+
will depend on the ability of this function to parse and interpret the date
311+
strings used.
312+
313+
314+
315+
316+
:class:`PlotPanel` methods
317+
=============================================
318+
319+
320+
.. method:: plot(x, y, **kws)
321+
322+
Draw a plot of the numpy arrays *x* and *y*, erasing any existing plot. The
323+
displayed curve for these data is called a *trace*. The :meth:`plot` method
324+
has many optional parameters, all using keyword/value argument. Since most
325+
of these are shared with the :meth:`oplot` method, the full set of parameters
326+
is given in :ref:`Table of Plot Arguments <plotopt_table>`
327+
328+
.. method:: oplot(x, y, **kws)
329+
330+
Draw a plot of the numpy arrays *x* and *y*, overplotting any existing
331+
plot, so that both traces are visible.
332+
333+
The :meth:`oplot` method has many optional parameters, as listed in
334+
:ref:`Table of Plot Arguments <plotopt_table>`
335+
336+
.. method:: update_line(trace, x, y, yaxes=1, side=None, update_limits=True, draw=False)
270337

271338
update an existing trace.
272339

273340
:param trace: integer index for the trace (0 is the first trace)
274341
:param x: array of x values
275342
:param y: array of y values
276-
:param side: which y axis to use ('left', 'right', 'right2', or 'right3').
343+
:param side: which y axis to use. See :ref:`sect_yaxes_side`.
344+
:param yaxes: which y axis to use.
277345
:param update_limits: whether to force an update of the limits.
278346
:param draw: whether to force a redrawing of the canvas.
279347

@@ -306,20 +374,21 @@ same meaning, as indicated by the right-most column.
306374

307375
Clear the plot.
308376

309-
.. method:: add_text(text, x, y, side='left', rotation=None, ha='left', va='center', family=None, **kws)
377+
.. method:: add_text(text, x, y, yaxes=1, side=None, rotation=None, ha='left', va='center', family=None, **kws)
310378

311379
add text to the plot.
312380

313381
:param text: text to write
314382
:param x: x coordinate for text
315383
:param y: y coordinate for text
316-
:param side: which axis to use ('left' or 'right') for coordinates.
384+
:param side: which y-axes to use for coordinates. See :ref:`sect_yaxes_side`.
385+
:param yaxes: which y-axes to use for coordinates.
317386
:param rotation: text rotation: angle in degrees or 'vertical' or 'horizontal'
318387
:param ha: horizontal alignment ('left', 'center', 'right')
319388
:param va: vertical alignment ('top', 'center', 'bottom', 'baseline')
320389
:param family: name of font family ('serif', 'sans-serif', etc)
321390

322-
.. method:: add_arrow(x1, y1, x2, y2, side='left', shape='full', color='black', wdith=0.01, head_width=0.03, overhang=0)
391+
.. method:: add_arrow(x1, y1, x2, y2, yaxes=1, side=None, shape='full', color='black', wdith=0.01, head_width=0.03, overhang=0)
323392

324393

325394
draw arrow from (x1, y1) to (x2, y2).
@@ -328,22 +397,24 @@ same meaning, as indicated by the right-most column.
328397
:param y1: starting y coordinate
329398
:param x2: endnig x coordinate
330399
:param y2: ending y coordinate
331-
:param side: which axis to use ('left' or 'right') for coordinates.
400+
:param side: which y-axes to use for coordinates. See :ref:`sect_yaxes_side`.
401+
:param yaxes: which y-axes to use for coordinates.
332402
:param shape: arrow head shape ('full', 'left', 'right')
333403
:param color: arrow fill color ('black')
334404
:param width: width of arrow line (in points. default=0.01)
335405
:param head_width: width of arrow head (in points. default=0.1)
336406
:param overhang: amount the arrow is swept back (in points. default=0)
337407

338408

339-
.. method:: set_xylims(limits[, axes=None[, side=None]])
409+
.. method:: set_xylims(limits[, axes=None[, side=None, yaxes=1]])
340410

341411
Set the x and y limits for a plot based on a 2x2 list.
342412

343413
:param limits: x and y limits
344414
:type limits: a 4-element list: [xmin, xmax, ymin, ymax]
345415
:param axes: instance of matplotlib axes to use (i.e, for right or left side y axes)
346-
:param side: set to 'right' to get right-hand axes.
416+
:param side: which y-axes to use. See :ref:`sect_yaxes_side`.
417+
:param yaxes: which y-axis to use.
347418

348419
.. method:: get_xylims()
349420

@@ -395,33 +466,6 @@ same meaning, as indicated by the right-most column.
395466
reset the configuration to default settings.
396467

397468

398-
.. _sect_datetime:
399-
400-
Using date-time data with :func:`plot`
401-
===========================================
402-
403-
If the `x` values to be plotted holds date or time data, these can be handled in
404-
a few different formats. In order for the X-axis labels to be properly
405-
displayed as a string showing the date, the values must be eventually converted
406-
to a `matplotlib.dates` object, which uses a floating point number to represent
407-
the number of days since year 0, BCE. The `wxmplot` user is not expected to do
408-
this conversion.
409-
410-
The best way to specify datetime information is to use `datetime` objects
411-
from the `datetime` library. These will be automatically recognized and
412-
properly converted.
413-
414-
If the `x` data is a list or array of integers or floats and `use_dates=True` is
415-
used, the values will be interpreted as Unix timestamps (seconds since 1970),
416-
unless `dates_styles='dates'`, in which case they will be interpreted as
417-
`matplotlib.dates`.
418-
419-
Finally, it is possible to pass in a list or array of strings as `x`, and set
420-
`use_dates=True`. In this case, the `matplotlib.dates.datestr2num` function
421-
will be used convert the string. Of course, whether this actually works well
422-
will depend on the ability of this function to parse and interpret the date
423-
strings used.
424-
425469

426470

427471
:class:`PlotFrame`: a wx.Frame showing a :class:`PlotPanel`

0 commit comments

Comments
 (0)