Skip to content

Commit d7dece2

Browse files
authored
Update new-matplotlib-intro.rst
more cuts to material for brevity
1 parent d67eb38 commit d7dece2

1 file changed

Lines changed: 19 additions & 44 deletions

File tree

docs/day3/new-matplotlib-intro.rst

Lines changed: 19 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -347,51 +347,26 @@ The outputs look the same for both of these examples because the plot type was c
347347
plt.show()
348348

349349

350-
Subplots
351-
~~~~~~~~
350+
.. admonition:: Subplots and Subplot Mosaics
352351

353-
A prime example of a feature only available through the explicit API is subplots, which support and format 2 or more separate sets of axes on the same figure. For the standard ``fig, ax = plt.subplots(nrows=nrows, ncols=ncols)`` command, the shape of ``ax`` will be
354-
355-
* 2D if both ``nrows`` and ``ncols`` are given,
356-
* 1D if only one of either ``nrows`` or ``ncols`` is provided, or
357-
* 0D (not iterable) if neither are given.
358-
359-
.. jupyter-execute::
360-
361-
import numpy as np
362-
import matplotlib.pyplot as plt
363-
%matplotlib inline
364-
x = np.linspace(0,2*np.pi, 50)
365-
fig, ax = plt.subplots(nrows=2, sharex=True)
366-
fig.subplots_adjust(hspace=0.05) #reduces space between 2 plots
367-
ax[0].plot(x,3+3*np.sin(x),'b-', label=r'3+3$\times$sin(x)')
368-
ax[1].plot(x, 2+2*np.cos(x), 'r-.', label=r'2+2$\times$cos(x)')
369-
ax[1].set_xlabel('x [rads]')
370-
for a in ax:
371-
a.legend()
372-
a.set_ylabel('y')
373-
ax[0].set_title('Demo Plot - Subplots')
374-
plt.show()
375-
376-
Other subplot creation functions are available if you need more flexibility between subplots in terms of formatting and coordinate projections. Generally, all methods support shared axes and allow non-Cartesian coordinate projections, but not all methods allow varying projections per plot, and only a couple include support for row- or column-spanning subplots.
377-
378-
The following table summarizes all the available subplot creation methods and their capabilities:
379-
380-
======================== =============== ======================== ================================ ========================
381-
Supported features
382-
------------------------ --------------------------------------------------------------------------------------------------
383-
Method Iterable Axes Coordinate projections Row-/column-spanning subplots Max number of subplots
384-
======================== =============== ======================== ================================ ========================
385-
``plt.subplots()`` Yes one for all subplots requires ``fig.add_gridspec()`` arbitrary
386-
``plt.subplot()`` No can vary per subplot requires ``fig.add_gridspec()`` 9
387-
``fig.add_subplot()`` No can vary per subplot requires ``fig.add_gridspec()`` 9
388-
``plt.subplot_mosaic()`` Yes can vary per subplot Yes arbitrary
389-
``plt.subplot2grid()``\* Yes one for all subplots Yes arbitrary
390-
======================== =============== ======================== ================================ ========================
391-
392-
\*Note: ``plt.subplot_mosaic()`` is recommended over ``plt.subplot2grid()``.
393-
394-
.. admonition:: Mathtext and String Insertion
352+
A prime example of a feature only available through the explicit API is subplots, which support and format 2 or more separate sets of axes on the same figure. The `Matplotlib documentation on subplots and subplot mosaics <https://matplotlib.org/stable/users/explain/axes/arranging_axes.html>`__ is extensive and fairly straightforward, so this topic will not be covered in depth here. The table below summarizes all the available subplot creation methods that you may see and their capabilities so you can compare them:
353+
354+
======================== =============== ======================== ================================ ========================
355+
Supported features
356+
------------------------ --------------------------------------------------------------------------------------------------
357+
Method Iterable Axes Coordinate projections Row-/column-spanning subplots Max number of subplots
358+
======================== =============== ======================== ================================ ========================
359+
``plt.subplots()`` Yes one for all subplots requires ``fig.add_gridspec()`` arbitrary
360+
``plt.subplot()`` No can vary per subplot requires ``fig.add_gridspec()`` 9
361+
``fig.add_subplot()`` No can vary per subplot requires ``fig.add_gridspec()`` 9
362+
``plt.subplot_mosaic()`` Yes can vary per subplot Yes arbitrary
363+
``plt.subplot2grid()``\* Yes one for all subplots Yes arbitrary
364+
======================== =============== ======================== ================================ ========================
365+
366+
\*Note: ``plt.subplot_mosaic()`` is recommended over ``plt.subplot2grid()``.
367+
368+
369+
.. admonition:: Mathtext and String Insertion (Not covered by Matplotlib documentation)
395370
:collapsible:
396371

397372
Most journals expect that you typeset all variables and math scripts so they appear the same in your plots as in your main text, whether those symbols appear in the `axes labels, function labels, plot titles, or annotations. <https://matplotlib.org/stable/users/explain/text/text_intro.html>`__ Matplotlib now `supports most LaTeX math commands, <https://matplotlib.org/stable/users/explain/text/mathtext.html#mathtext>`__ but you need to know some basic LaTeX syntax, some of which is covered in that link. For more information, you can refer to `the WikiBooks documentation on LaTeX math <https://en.wikibooks.org/wiki/LaTeX/Mathematics>`__, starting with the Symbols section.

0 commit comments

Comments
 (0)