Skip to content

Commit 1f4ba46

Browse files
committed
Physical units descrip
1 parent b08e52d commit 1f4ba46

File tree

2 files changed

+55
-12
lines changed

2 files changed

+55
-12
lines changed

docs/tight.ipynb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
"source": [
1616
"Matplotlib has a `tight layout algorithm <https://matplotlib.org/3.1.1/tutorials/intermediate/tight_layout_guide.html>`__ that adjusts the space between subplots and around the figure edge to accomodate labels and plotted content.\n",
1717
"\n",
18-
"ProPlot introduces a *new* tight layout algorithm that permits *variable figure dimensions* and *variable spacing* between subplot rows and columns (see `~proplot.subplots.FlexibleGridSpec`). This allows the algorithm to preserve subplot aspect ratios, colorbar and panel widths, and optionally, subplot physical dimensions, all without producing extra whitespace."
18+
"ProPlot introduces a *new* tight layout algorithm that permits *variable figure dimensions* and *variable spacing* between subplot rows and columns (see `~proplot.subplots.FlexibleGridSpec`). This allows the algorithm to preserve subplot aspect ratios, colorbar and panel widths, and optionally, subplot physical dimensions, all without producing extra whitespace. It is applied to all figured by default -- to turn it off, pass ``tight=False`` to `~proplot.subplots.Figure` or change the :rcraw:`tight` setting."
1919
]
2020
},
2121
{
2222
"cell_type": "markdown",
2323
"metadata": {},
2424
"source": [
25-
"## The new algorithm"
25+
"## Reference axes"
2626
]
2727
},
2828
{
@@ -31,7 +31,7 @@
3131
"raw_mimetype": "text/restructuredtext"
3232
},
3333
"source": [
34-
"To fix the figure dimension(s), pass `width`, `height`, and/or `figsize` to `~proplot.subplots.subplots`. To fix the reference subplot dimension(s), use `axwidth`, `axheight`, and/or `aspect`. To set the reference subplot, use `ref` (default is ``1``, i.e. the subplot in the upper left corner). To turn off the algorithm, pass ``tight=False`` to `~proplot.subplots.Figure` or change the :rcraw:`tight` setting.\n",
34+
"To fix the figure dimension(s), pass `width`, `height`, and/or `figsize` to `~proplot.subplots.subplots`. To fix the reference subplot dimension(s), use `axwidth`, `axheight`, and/or `aspect`. To set the reference subplot, use `ref` (default is ``1``, i.e. the subplot in the upper left corner). When you specify just `width` or `axwidth`, the figure *height* is adjusted automatically to accommodate `aspect`. When you specify just `height` or `axheight`, the figure *width* is adjusted automatically.\n",
3535
"\n",
3636
"If the `aspect ratio mode <https://matplotlib.org/2.0.2/examples/pylab_examples/equal_aspect_ratio.html>`__ for the `ref` subplot is set to ``'equal'``, as with :ref:`Geographic and polar plots` and `~matplotlib.axes.Axes.imshow` plots, the existing aspect will be used instead of the input `aspect`.\n",
3737
"\n",
@@ -62,7 +62,7 @@
6262
"source": [
6363
"import proplot as plot\n",
6464
"for ref in (3,2):\n",
65-
" f, axs = plot.subplots([[1,1,2],[1,1,3],[4,5,3],[4,6,6],[7,7,8]], ref=ref, axwidth=1.1, span=False)\n",
65+
" f, axs = plot.subplots([[1,1,2],[1,1,3],[4,5,3],[4,6,6],[7,7,8]], wratios=(1.5,1,1.5), ref=ref, axwidth=1.1, span=False)\n",
6666
" axs[ref-1].format(title='reference axes', titleweight='bold', titleloc='uc', titlecolor='red9')\n",
6767
" axs.format(xlabel='xlabel', ylabel='ylabel', suptitle='Super title')\n",
6868
" axs[0].format(xlabel='xlabel\\nxlabel\\nxlabel')\n",
@@ -87,14 +87,16 @@
8787
"source": [
8888
"When you pass a spacing argument like `left`, `right`, `top`, `bottom`, `wspace`, or `hspace` to `~proplot.subplots.Figure` or `~proplot.subplots.FlexibleGridSpec`, that value is *always respected* -- the tight layout algorithm will not change it.\n",
8989
"\n",
90-
"For example, if you pass ``left='2em'`` to `~proplot.subplots.subplots`, the left margin is fixed but the right, bottom, and top margins are determined automatically. Similarly, if you pass ``wspace=('3em', None)`` and ``ncols=3`` to `~proplot.subplots.subplots`, the space between the first two columns is fixed, while the space between the second two columns is determined automatically. "
90+
"For example, if you pass ``left='2em'`` to `~proplot.subplots.subplots`, the left margin is fixed but the right, bottom, and top margins are determined automatically. Similarly, if you pass ``wspace=('3em', None)`` and ``ncols=3`` to `~proplot.subplots.subplots`, the space between the first two columns is fixed, while the space between the second two columns is determined automatically.\n",
91+
"\n",
92+
"The figure width and height are constrained similarly. If you pass both a figure `width` and `height` or a subplot `axwidth` and `axheight`, the `aspect` is ignored. If you just pass one of the `width`, `height`, `axwidth`, or `axheight`, the aspect ratio is preserved and the other dimension is adjusted accordingly."
9193
]
9294
},
9395
{
9496
"cell_type": "markdown",
9597
"metadata": {},
9698
"source": [
97-
"## Physical units engine"
99+
"## Manual figure layout"
98100
]
99101
},
100102
{
@@ -103,7 +105,7 @@
103105
"raw_mimetype": "text/restructuredtext"
104106
},
105107
"source": [
106-
"Matplotlib requires you to specify the figure size in *inches*, which must be confusing for users outside of the U.S. ProPlot supports *arbitrary physical units* for controlling the figure `width` and `height`; the reference subplot `axwidth` and `axheight`; the gridspec spacing values `left`, `right`, `bottom`, `top`, `wspace`, and `hspace`; and in a few other places.\n",
108+
"The figure layout can also be configured manually. ProPlot supports *arbitrary physical units* for controlling the figure `width` and `height`; the reference subplot `axwidth` and `axheight`; the gridspec spacing values `left`, `right`, `bottom`, `top`, `wspace`, and `hspace`; and in a few other places.\n",
107109
"\n",
108110
"If a sizing argument is numeric, the units are inches or points, and if string, the units are interpreted by `~proplot.utils.units`. A table of acceptable units is found in the `~proplot.utils.units` documentation. They include centimeters, millimeters, pixels, and light years (because why not?)."
109111
]

docs/why.rst

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ ProPlot's core mission
66
is to improve upon the parts of matplotlib that
77
tend to be cumbersome or repetitive
88
for power users.
9-
This page enumerates these limitations and
10-
describes how ProPlot addresses them.
9+
This page enumerates the stickiest of these limitations
10+
and describes how ProPlot addresses them.
11+
12+
..
13+
This page is not comprehensive --
14+
see the User Guide for a comprehensive overview
15+
with worked examples.
1116
1217
..
1318
To start using these new features, see
@@ -279,7 +284,7 @@ to various plotting methods:
279284
* All 1d plotting methods accept a `cycle` keyword argument interpreted by `~proplot.styletools.Cycle`. See :ref:`Color cycles` for details.
280285
* All 2d plotting methods accept a `cmap` keyword argument interpreted by `~proplot.styletools.Colormap`. See :ref:`Colormaps` for details.
281286
* 1d coordinate vectors passed to 2d plotting methods can be graticule *edges* or *centers*. When edges are passed to `~matplotlib.axes.Axes.contour` or `~matplotlib.axes.Axes.contourf`, centers are calculated from the edges. When centers are passed to `~matplotlib.axes.Axes.pcolor` or `~matplotlib.axes.Axes.pcolormesh`, *edges* are estimated from the centers.
282-
* ProPlot fixes the annoying `white-lines-between-filled-contours <https://stackoverflow.com/q/8263769/4970632>`__, `white-lines-between-pcolor-rectangles <https://stackoverflow.com/q/27092991/4970632>`__, and `white-lines-between-colorbar-levels <https://stackoverflow.com/q/15003353/4970632>`__ issues for `~matplotlib.axes.Axes.contouf` plots, `~matplotlib.axes.Axes.imshow` plots, and `~proplot.subplots.Figure` and `~proplot.axes.Axes` colorbars.
287+
* ProPlot fixes the annoying `white-lines-between-filled-contours <https://stackoverflow.com/q/8263769/4970632>`__, `white-lines-between-pcolor-rectangles <https://stackoverflow.com/q/27092991/4970632>`__, and `white-lines-between-colorbar-levels <https://stackoverflow.com/q/15003353/4970632>`__ issues for `~matplotlib.axes.Axes.contourf` plots, `~matplotlib.axes.Axes.imshow` plots, and `~proplot.subplots.Figure` and `~proplot.axes.Axes` colorbars.
283288

284289
See :ref:`1d plotting` and :ref:`2d plotting`
285290
for details.
@@ -314,9 +319,9 @@ This lets you apply all kinds of geographic plot settings, like coastlines, cont
314319
`~proplot.axes.ProjAxes` also
315320
overrides various plotting methods:
316321

317-
* ``globe=True`` can be passed to any 2D plotting command to enforce *global* coverage over the poles and across the longitude boundaries.
318-
* ``latlon=True`` is the new default for all `~proplot.axes.BasemapAxes` plotting methods.
319322
* ``transform=ccrs.PlateCarree()`` is the new default for all `~proplot.axes.GeoAxes` plotting methods.
323+
* ``latlon=True`` is the new default for all `~proplot.axes.BasemapAxes` plotting methods.
324+
* ``globe=True`` can be passed to any 2D plotting command to enforce *global* coverage over the poles and across the longitude boundaries.
320325

321326
See :ref:`Geographic and polar plots` for details.
322327

@@ -400,6 +405,42 @@ ProPlot comes packaged with several additional fonts. The new default font is He
400405

401406
ProPlot adds fonts to matplotlib by making use of a completely undocumented feature: the ``$TTFPATH`` environment variable (matplotlib adds ``.ttf`` and ``.otf`` font files from folders listed in ``$TTFPATH``). You can also use *your own* font files by dropping them in ``~/.proplot/fonts``.
402407

408+
Physical units engine
409+
=====================
410+
.. raw:: html
411+
412+
<h3>Problem</h3>
413+
414+
Matplotlib requires users to use
415+
*inches* for the figure size `figsize`. This must be confusing for users outside
416+
of the U.S.
417+
418+
Matplotlib also uses figure-relative units for the margins
419+
`left`, `right`, `bottom`, and `top`, and axes-relative units
420+
for the column and row spacing `wspace` and `hspace`.
421+
Relative units tend to require "tinkering" with meaningless numbers until you find the
422+
right one... and then if your figure size changes, you have to adjust them again.
423+
424+
.. raw:: html
425+
426+
<h3>Solution</h3>
427+
428+
ProPlot introduces the physical units engine `~proplot.utils.units`
429+
for interpreting `figsize`, `width`, `height`, `axwidth`, `axheight`,
430+
`left`, `right`, `top`, `bottom`, `wspace`, `hspace`, and arguments
431+
in a few other places. Acceptable units include inches, centimeters,
432+
millimeters, `points <https://en.wikipedia.org/wiki/Point_(typography)>`__,
433+
pixels, em-heights, and light years (because
434+
why not?). Em-heights are particularly useful, as labels already
435+
present can be useful *rulers* for figuring out the amount
436+
of space needed.
437+
438+
`~proplot.utils.units` is also used to convert settings
439+
passed to `~proplot.rctools.rc` from arbitrary physical units
440+
to *points* -- for example, :rcraw:`linewidth`, :rcraw:`ticklen`,
441+
:rcraw:`axes.titlesize`, and :rcraw:`axes.titlepad`.
442+
See :ref:`Configuring proplot` for details.
443+
403444
..
404445
...and much more!
405446
=================

0 commit comments

Comments
 (0)