|
26 | 26 | # |
27 | 27 | # UltraPlot works by `subclassing |
28 | 28 | # <https://docs.python.org/3/tutorial/classes.html#inheritance>`__ |
29 | | -# three fundamental matplotlib classes: :class:`ultraplot.figure.Figure` replaces |
30 | | -# :class:`matplotlib.figure.Figure`, :class:`ultraplot.axes.Axes` replaces :class:`matplotlib.axes.Axes`, |
31 | | -# and :class:`ultraplot.gridspec.GridSpec` replaces :class:`matplotlib.gridspec.GridSpec` |
| 29 | +# three fundamental matplotlib classes: :class:`~ultraplot.figure.Figure` replaces |
| 30 | +# :class:`matplotlib.figure.Figure`, :class:`~ultraplot.axes.Axes` replaces :class:`matplotlib.axes.Axes`, |
| 31 | +# and :class:`~ultraplot.gridspec.GridSpec` replaces :class:`matplotlib.gridspec.GridSpec` |
32 | 32 | # (see this `tutorial |
33 | 33 | # <https://matplotlib.org/stable/tutorials/intermediate/gridspec.html>`__ |
34 | 34 | # for more on gridspecs). |
35 | 35 | # |
36 | 36 | # To make plots with these classes, you must start with the top-level commands |
37 | 37 | # :func:`~ultraplot.ui.figure`, :func:`~ultraplot.ui.subplot`, or :func:`~ultraplot.ui.subplots`. These are |
38 | | -# modeled after the :func:`~matplotlib.pyplot` commands of the same name. As in |
39 | | -# :func:`~matplotlib.pyplot`, :func:`~ultraplot.ui.subplot` creates a figure and a single |
| 38 | +# modeled after the :mod:`~matplotlib.pyplot` commands of the same name. As in |
| 39 | +# :mod:`~matplotlib.pyplot`, :func:`~ultraplot.ui.subplot` creates a figure and a single |
40 | 40 | # subplot, :func:`~ultraplot.ui.subplots` creates a figure and a grid of subplots, and |
41 | 41 | # :func:`~ultraplot.ui.figure` creates an empty figure that can be subsequently filled |
42 | 42 | # with subplots. A minimal example with just one subplot is shown below. |
|
85 | 85 | # fig = uplt.figure(suptitle='Single subplot') # equivalent to above |
86 | 86 | # ax = fig.subplot(xlabel='x axis', ylabel='y axis') |
87 | 87 | ax.plot(data, lw=2) |
| 88 | +fig.show() |
88 | 89 |
|
89 | 90 |
|
90 | 91 | # %% [raw] raw_mimetype="text/restructuredtext" |
|
95 | 96 | # |
96 | 97 | # Similar to matplotlib, subplots can be added to figures one-by-one |
97 | 98 | # or all at once. Each subplot will be an instance of |
98 | | -# :class:`ultraplot.axes.Axes`. To add subplots all at once, use |
99 | | -# :func:`ultraplot.figure.Figure.add_subplots` (or its shorthand, |
100 | | -# :func:`ultraplot.figure.Figure.subplots`). Note that under the hood, the top-level |
101 | | -# UltraPlot command :func:`~ultraplot.ui.subplots` simply calls :class::func:`~ultraplot.ui.figure` |
102 | | -# followed by :func:`ultraplot.figure.Figure.add_subplots`. |
| 99 | +# :class:`~ultraplot.axes.Axes`. To add subplots all at once, use |
| 100 | +# :func:`~ultraplot.figure.Figure.add_subplots` (or its shorthand, |
| 101 | +# :func:`~ultraplot.figure.Figure.subplots`). Note that under the hood, the top-level |
| 102 | +# UltraPlot command :func:`~ultraplot.ui.subplots` simply calls :func:`~ultraplot.ui.figure` |
| 103 | +# followed by :func:`~ultraplot.figure.Figure.add_subplots`. |
103 | 104 | # |
104 | 105 | # * With no arguments, :func:`~ultraplot.figure.Figure.add_subplots` returns a subplot |
105 | 106 | # generated from a 1-row, 1-column :class:`~ultraplot.gridspec.GridSpec`. |
|
109 | 110 | # * With `array`, :func:`~ultraplot.figure.Figure.add_subplots` returns an arbitrarily |
110 | 111 | # complex grid of subplots from a :class:`~ultraplot.gridspec.GridSpec` with matching |
111 | 112 | # geometry. Here `array` is a 2D array representing a "picture" of the subplot |
112 | | -# layout, where each unique integer indicates a `~matplotlib.gridspec.GridSpec` |
| 113 | +# layout, where each unique integer indicates a :class:`~matplotlib.gridspec.GridSpec` |
113 | 114 | # slot occupied by the corresponding subplot and ``0`` indicates an empty space. |
114 | 115 | # The returned subplots are contained in a :class:`~ultraplot.gridspec.SubplotGrid` |
115 | 116 | # (:ref:`see below <ug_subplotgrid>` for details). |
116 | 117 | # |
117 | | -# To add subplots one-by-one, use the :func:`ultraplot.figure.Figure.add_subplot` |
118 | | -# command (or its shorthand :func:`ultraplot.figure.Figure.subplot`). |
| 118 | +# To add subplots one-by-one, use the :func:`~ultraplot.figure.Figure.add_subplot` |
| 119 | +# command (or its shorthand :func:`~ultraplot.figure.Figure.subplot`). |
119 | 120 | # |
120 | 121 | # * With no arguments, :func:`~ultraplot.figure.Figure.add_subplot` returns a subplot |
121 | 122 | # generated from a 1-row, 1-column :class:`~ultraplot.gridspec.GridSpec`. |
|
124 | 125 | # as in matplotlib. Note that unlike matplotlib, the geometry must be compatible |
125 | 126 | # with the geometry implied by previous :func:`~ultraplot.figure.Figure.add_subplot` calls. |
126 | 127 | # * With a :class:`~matplotlib.gridspec.SubplotSpec` generated by indexing a |
127 | | -# :class:`ultraplot.gridspec.GridSpec`, :func:`~ultraplot.figure.Figure.add_subplot` returns a |
| 128 | +# :class:`~ultraplot.gridspec.GridSpec`, :func:`~ultraplot.figure.Figure.add_subplot` returns a |
128 | 129 | # subplot at the corresponding location. Note that unlike matplotlib, only |
129 | 130 | # one :func:`~ultraplot.figure.Figure.gridspec` can be used with each figure. |
130 | 131 | # |
|
156 | 157 | fig.format( |
157 | 158 | suptitle="Simple subplot grid", title="Title", xlabel="x axis", ylabel="y axis" |
158 | 159 | ) |
| 160 | +fig.show() |
159 | 161 | # fig.save('~/example1.png') # save the figure |
160 | 162 | # fig.savefig('~/example1.png') # alternative |
161 | 163 |
|
|
181 | 183 | ylabel="ylabel", |
182 | 184 | ) |
183 | 185 | axs[2].plot(data, lw=2) |
| 186 | +fig.show() |
184 | 187 | # fig.save('~/example2.png') # save the figure |
185 | 188 | # fig.savefig('~/example2.png') # alternative |
186 | 189 |
|
|
203 | 206 | suptitle="Really complex subplot grid", xlabel="xlabel", ylabel="ylabel", abc=True |
204 | 207 | ) |
205 | 208 | axs[0].plot(data, lw=2) |
| 209 | +fig.show() |
206 | 210 | # fig.save('~/example3.png') # save the figure |
207 | 211 | # fig.savefig('~/example3.png') # alternative |
208 | 212 |
|
|
222 | 226 | fig.format( |
223 | 227 | suptitle="Subplot grid with a GridSpec", xlabel="xlabel", ylabel="ylabel", abc=True |
224 | 228 | ) |
| 229 | +fig.show() |
225 | 230 | # fig.save('~/example4.png') # save the figure |
226 | 231 | # fig.savefig('~/example4.png') # alternative |
227 | 232 |
|
|
234 | 239 | # If you create subplots all-at-once with e.g. :func:`~ultraplot.ui.subplots`, |
235 | 240 | # UltraPlot returns a :class:`~ultraplot.gridspec.SubplotGrid` of subplots. This list-like, |
236 | 241 | # array-like object provides some useful features and unifies the behavior of the |
237 | | -# three possible return types used by `matplotlib.pyplot.subplots`: |
| 242 | +# three possible return types used by :func:`matplotlib.pyplot.subplots`: |
238 | 243 | # |
239 | 244 | # * :class:`~ultraplot.gridspec.SubplotGrid` behaves like a scalar when it is singleton. |
240 | 245 | # In other words, if you make a single subplot with ``fig, axs = uplt.subplots()``, |
|
255 | 260 | # :func:`~ultraplot.gridspec.SubplotGrid.panel_axes`, |
256 | 261 | # :func:`~ultraplot.gridspec.SubplotGrid.inset_axes`, |
257 | 262 | # :func:`~ultraplot.gridspec.SubplotGrid.altx`, and :func:`~ultraplot.gridspec.SubplotGrid.alty`. |
258 | | -# In the below example, we use `ultraplot.gridspec.SubplotGrid.format` on the grid |
| 263 | +# In the below example, we use :func:`~ultraplot.gridspec.SubplotGrid.format` on the grid |
259 | 264 | # returned by :func:`~ultraplot.ui.subplots` to format different subgroups of subplots |
260 | 265 | # (:ref:`see below <ug_format>` for more on the format command). |
261 | 266 | # |
|
264 | 269 | # If you create subplots one-by-one with :func:`~ultraplot.figure.Figure.subplot` or |
265 | 270 | # :func:`~ultraplot.figure.Figure.add_subplot`, a :class:`~ultraplot.gridspec.SubplotGrid` |
266 | 271 | # containing the numbered subplots is available via the |
267 | | -# :class:`ultraplot.figure.Figure.subplotgrid` property. As with subplots made |
| 272 | +# :class:`~ultraplot.figure.Figure.subplotgrid` property. As with subplots made |
268 | 273 | # all-at-once, the subplots in the grid are sorted by :func:`~ultraplot.axes.Axes.number`. |
269 | 274 |
|
270 | 275 | # %% |
|
294 | 299 | axs[1, :1].format(fc="sky blue") |
295 | 300 | axs[-1, -1].format(fc="gray4", grid=False) |
296 | 301 | axs[0].plot((state.rand(50, 10) - 0.5).cumsum(axis=0), cycle="Grays_r", lw=2) |
| 302 | +fig.show() |
297 | 303 |
|
298 | 304 |
|
299 | 305 | # %% [raw] raw_mimetype="text/restructuredtext" |
|
305 | 311 | # Matplotlib includes `two different interfaces |
306 | 312 | # <https://matplotlib.org/stable/api/index.html>`__ for plotting stuff: |
307 | 313 | # a python-style object-oriented interface with axes-level commands |
308 | | -# like :func:`matplotlib.axes.Axes.plot`, and a MATLAB-style :func:`~matplotlib.pyplot` interface |
| 314 | +# like :method:`matplotlib.axes.Axes.plot`, and a MATLAB-style :mod:`~matplotlib.pyplot` interface |
309 | 315 | # with global commands like :func:`matplotlib.pyplot.plot` that track the "current" axes. |
310 | | -# UltraPlot builds upon the python-style interface using the `ultraplot.axes.PlotAxes` |
| 316 | +# UltraPlot builds upon the python-style interface using the `~ultraplot.axes.PlotAxes` |
311 | 317 | # class. Since every axes used by UltraPlot is a child of :class:`~ultraplot.axes.PlotAxes`, we |
312 | 318 | # are able to add features directly to the axes-level commands rather than relying |
313 | 319 | # on a separate library of commands (note that while some of these features may be |
314 | | -# accessible via :func:`~matplotlib.pyplot` commands, this is not officially supported). |
| 320 | +# accessible via :mod:`~matplotlib.pyplot` commands, this is not officially supported). |
315 | 321 | # |
316 | 322 | # For the most part, the features added by :class:`~ultraplot.axes.PlotAxes` represent |
317 | 323 | # a *superset* of matplotlib. If you are not interested, you can use the plotting |
|
353 | 359 | suptitle="Quick plotting demo", |
354 | 360 | ) |
355 | 361 | fig.colorbar(m, loc="b", label="label") |
| 362 | +fig.show() |
356 | 363 |
|
357 | 364 |
|
358 | 365 | # %% [raw] raw_mimetype="text/restructuredtext" |
|
364 | 371 | # Matplotlib includes `two different interfaces |
365 | 372 | # <https://matplotlib.org/stable/api/index.html>`__ for formatting stuff: |
366 | 373 | # a "python-style" object-oriented interface with instance-level commands |
367 | | -# like `matplotlib.axes.Axes.set_title`, and a "MATLAB-style" interface |
| 374 | +# like :func:`matplotlib.axes.Axes.set_title`, and a "MATLAB-style" interface |
368 | 375 | # that tracks current axes and provides global commands like |
369 | | -# `matplotlib.pyplot.title`. |
| 376 | +# :func:`matplotlib.pyplot.title`. |
370 | 377 | # |
371 | 378 | # UltraPlot provides the ``format`` command as an |
372 | 379 | # alternative "python-style" command for formatting a variety of plot elements. |
|
380 | 387 | # |
381 | 388 | # * Figure settings. These are related to row labels, column labels, and |
382 | 389 | # figure "super" titles -- for example, ``fig.format(suptitle='Super title')``. |
383 | | -# See `ultraplot.figure.Figure.format` for details. |
| 390 | +# See :func:`~ultraplot.figure.Figure.format` for details. |
384 | 391 | # |
385 | 392 | # * General axes settings. These are related to background patches, |
386 | 393 | # a-b-c labels, and axes titles -- for example, ``ax.format(title='Title')`` |
387 | | -# See `ultraplot.axes.Axes.format` for details. |
| 394 | +# See :func:`~ultraplot.axes.Axes.format` for details. |
388 | 395 | # |
389 | | -# * Cartesian axes settings (valid only for `~ultraplot.axes.CartesianAxes`). |
| 396 | +# * Cartesian axes settings (valid only for :class:`~ultraplot.axes.CartesianAxes`). |
390 | 397 | # These are related to *x* and *y* axis ticks, spines, bounds, and labels -- |
391 | 398 | # for example, ``ax.format(xlim=(0, 5))`` changes the x axis bounds. |
392 | | -# See :func:`ultraplot.axes.CartesianAxes.format` and |
| 399 | +# See :func:`~ultraplot.axes.CartesianAxes.format` and |
393 | 400 | # :ref:`this section <ug_cartesian>` for details. |
394 | 401 | # |
395 | 402 | # * Polar axes settings (valid only for :class:`~ultraplot.axes.PolarAxes`). |
396 | 403 | # These are related to azimuthal and radial grid lines, bounds, and labels -- |
397 | 404 | # for example, ``ax.format(rlim=(0, 10))`` changes the radial bounds. |
398 | | -# See `ultraplot.axes.PolarAxes.format` |
| 405 | +# See :func:`~ultraplot.axes.PolarAxes.format` |
399 | 406 | # and :ref:`this section <ug_polar>` for details. |
400 | 407 | # |
401 | | -# * Geographic axes settings (valid only for `~ultraplot.axes.GeoAxes`). |
| 408 | +# * Geographic axes settings (valid only for :class:`~ultraplot.axes.GeoAxes`). |
402 | 409 | # These are related to map bounds, meridian and parallel lines and labels, |
403 | 410 | # and geographic features -- for example, ``ax.format(latlim=(0, 90))`` |
404 | | -# changes the meridional bounds. See `ultraplot.axes.GeoAxes.format` |
| 411 | +# changes the meridional bounds. See :func:`~ultraplot.axes.GeoAxes.format` |
405 | 412 | # and :ref:`this section <ug_geoformat>` for details. |
406 | 413 | # |
407 | 414 | # * :func:`~ultraplot.config.rc` settings. Any keyword matching the name |
|
414 | 421 | # See :ref:`this section <ug_config>` for more on rc settings. |
415 | 422 | # |
416 | 423 | # A ``format`` command is available on every figure and axes. |
417 | | -# `ultraplot.figure.Figure.format` accepts both figure and axes |
| 424 | +# :func:`~ultraplot.figure.Figure.format` accepts both figure and axes |
418 | 425 | # settings (applying them to each numbered subplot by default). |
419 | | -# Similarly, `ultraplot.axes.Axes.format` accepts both axes and figure |
420 | | -# settings. There is also a `ultraplot.gridspec.SubplotGrid.format` |
| 426 | +# Similarly, :func:`~ultraplot.axes.Axes.format` accepts both axes and figure |
| 427 | +# settings. There is also a :func:`~ultraplot.gridspec.SubplotGrid.format` |
421 | 428 | # command that can be used to change settings for a subset of |
422 | 429 | # subplots -- for example, ``axs[:2].format(xtickminor=True)`` |
423 | 430 | # turns on minor ticks for the first two subplots (see |
|
463 | 470 | xtickminor=False, |
464 | 471 | ygridminor=True, |
465 | 472 | ) |
| 473 | +fig.show() |
466 | 474 |
|
467 | 475 | # %% [raw] raw_mimetype="text/restructuredtext" |
468 | 476 | # .. _ug_rc: |
|
471 | 479 | # ------------------- |
472 | 480 | # |
473 | 481 | # A dictionary-like object named :func:`~ultraplot.config.rc` is created when you import |
474 | | -# UltraPlot. :func:`~ultraplot.config.rc` is similar to the matplotlib `~matplotlib.rcParams` |
| 482 | +# UltraPlot. :func:`~ultraplot.config.rc` is similar to the matplotlib :data:`~matplotlib.rcParams` |
475 | 483 | # dictionary, but can be used to change both `matplotlib settings |
476 | 484 | # <https://matplotlib.org/stable/tutorials/introductory/customizing.html>`__ and |
477 | 485 | # :ref:`ultraplot settings <ug_rcUltraPlot>`. The matplotlib-specific settings are |
478 | | -# stored in :func:`~ultraplot.config.rc_matplotlib` (our name for `matplotlib.rcParams`) and |
479 | | -# the UltraPlot-specific settings are stored in `~ultraplot.config.rc_UltraPlot`. |
| 486 | +# stored in :func:`~ultraplot.config.rc_matplotlib` (our name for :data:`~matplotlib.rcParams`) and |
| 487 | +# the UltraPlot-specific settings are stored in :class:`~ultraplot.config.rc_ultraplot`. |
480 | 488 | # UltraPlot also includes a :rcraw:`style` setting that can be used to |
481 | 489 | # switch between `matplotlib stylesheets |
482 | 490 | # <https://matplotlib.org/stable/gallery/style_sheets/style_sheets_reference.html>`__. |
483 | 491 | # See the :ref:`configuration section <ug_config>` for details. |
484 | 492 | # |
485 | 493 | # To modify a setting for just one subplot or figure, you can pass it to |
486 | | -# `ultraplot.axes.Axes.format` or `ultraplot.figure.Figure.format`. To temporarily |
| 494 | +# :func:`~ultraplot.axes.Axes.format` or :func:`~ultraplot.figure.Figure.format`. To temporarily |
487 | 495 | # modify setting(s) for a block of code, use :func:`~ultraplot.config.Configurator.context`. |
488 | 496 | # To modify setting(s) for the entire python session, just assign it to the |
489 | 497 | # :func:`~ultraplot.config.rc` dictionary or use :func:`~ultraplot.config.Configurator.update`. |
|
530 | 538 | titleloc="r", |
531 | 539 | titlecolor="gray7", |
532 | 540 | ) |
| 541 | +fig.show() |
533 | 542 |
|
534 | 543 | # Reset persistent modifications from head of cell |
535 | 544 | uplt.rc.reset() |
|
554 | 563 | for ax, style in zip(axs, styles): |
555 | 564 | ax.format(style=style, xlabel="xlabel", ylabel="ylabel", title=style) |
556 | 565 | ax.plot(data, linewidth=3) |
| 566 | +fig.show() |
0 commit comments