11.. _howto-faq :
22
3- *****
4- Howto
5- *****
3+ ******
4+ How-To
5+ ******
66
77.. contents ::
88 :backlinks: none
@@ -45,12 +45,14 @@ Save transparent figures
4545----------------------------------
4646
4747The :meth: `~matplotlib.pyplot.savefig ` command has a keyword argument
48- *transparent * which, if True, will make the figure and axes
48+ *transparent * which, if ' True' , will make the figure and axes
4949backgrounds transparent when saving, but will not affect the displayed
50- image on the screen. If you need finer grained control, eg you do not
51- want full transparency or you to affect the screen displayed version
52- as well, you can set the alpha properties directly. The figure has a
53- :class: `matplotlib.patches.Rectangle ` instance called *patch *
50+ image on the screen.
51+
52+ If you need finer grained control, eg you do not want full transparency
53+ or you want to affect the screen displayed version as well, you can set
54+ the alpha properties directly. The figure has a
55+ :class: `~matplotlib.patches.Rectangle ` instance called *patch *
5456and the axes has a Rectangle instance called *patch *. You can set
5557any property on them directly (*facecolor *, *edgecolor *, *linewidth *,
5658*linestyle *, *alpha *). Eg::
@@ -85,7 +87,7 @@ You can give the :class:`~matplotlib.backends.backend_pdf.PdfPages`
8587object to :func: `~matplotlib.pyplot.savefig `, but you have to specify
8688the format::
8789
88- savefig(pp, format='pdf')
90+ plt. savefig(pp, format='pdf')
8991
9092An easier way is to call
9193:meth: `PdfPages.savefig <matplotlib.backends.backend_pdf.PdfPages.savefig> `::
@@ -138,7 +140,7 @@ The other parameters you can configure are, with their defaults
138140If you want additional control, you can create an
139141:class: `~matplotlib.axes.Axes ` using the
140142:func: `~matplotlib.pyplot.axes ` command (or equivalently the figure
141- :meth: `matplotlib.figure.Figure.add_axes ` method), which allows you to
143+ :meth: `~ matplotlib.figure.Figure.add_axes ` method), which allows you to
142144specify the location explicitly::
143145
144146 ax = fig.add_axes([left, bottom, width, height])
@@ -149,26 +151,34 @@ where all values are in fractional (0 to 1) coordinates. See
149151.. _howto-auto-adjust :
150152
151153Automatically make room for tick labels
152- ----------------------------------------------------
154+ ---------------------------------------
155+
156+ .. note ::
157+ This is now easier to handle than ever before.
158+ Calling :func: `~matplotlib.pyplot.tight_layout ` can fix many common
159+ layout issues. See the :ref: `plotting-guide-tight-layout `.
160+
161+ The information below is kept here in case it is useful for other
162+ purposes.
153163
154164In most use cases, it is enough to simply change the subplots adjust
155165parameters as described in :ref: `howto-subplots-adjust `. But in some
156166cases, you don't know ahead of time what your tick labels will be, or
157167how large they will be (data and labels outside your control may be
158168being fed into your graphing application), and you may need to
159169automatically adjust your subplot parameters based on the size of the
160- tick labels. Any :class: `matplotlib.text.Text ` instance can report
170+ tick labels. Any :class: `~ matplotlib.text.Text ` instance can report
161171its extent in window coordinates (a negative x coordinate is outside
162172the window), but there is a rub.
163173
164- The :class: `matplotlib.backend_bases.RendererBase ` instance, which is
174+ The :class: `~ matplotlib.backend_bases.RendererBase ` instance, which is
165175used to calculate the text size, is not known until the figure is
166- drawn (:meth: `matplotlib.figure.Figure.draw `). After the window is
176+ drawn (:meth: `~ matplotlib.figure.Figure.draw `). After the window is
167177drawn and the text instance knows its renderer, you can call
168- :meth: `matplotlib.text.Text.get_window_extent `. One way to solve
178+ :meth: `~ matplotlib.text.Text.get_window_extent `. One way to solve
169179this chicken and egg problem is to wait until the figure is draw by
170180connecting
171- (:meth: `matplotlib.backend_bases.FigureCanvasBase.mpl_connect `) to the
181+ (:meth: `~ matplotlib.backend_bases.FigureCanvasBase.mpl_connect `) to the
172182"on_draw" signal (:class: `~matplotlib.backend_bases.DrawEvent `) and
173183get the window extent there, and then do something with it, eg move
174184the left of the canvas over; see :ref: `event-handling-tutorial `.
@@ -183,7 +193,7 @@ over so that the tick labels fit in the figure
183193.. _howto-ticks :
184194
185195Configure the tick linewidths
186- ---------------------------------------
196+ -----------------------------
187197
188198In matplotlib, the ticks are *markers *. All
189199:class: `~matplotlib.lines.Line2D ` objects support a line (solid,
@@ -209,7 +219,7 @@ are ``markerfacecolor``, ``markeredgecolor``, ``markeredgewidth``,
209219.. _howto-align-label :
210220
211221Align my ylabels across multiple subplots
212- ---------------------------------------------------
222+ -----------------------------------------
213223
214224If you have multiple subplots over one another, and the y data have
215225different scales, you can often get ylabels that do not align
@@ -226,7 +236,7 @@ setting in the right subplots.
226236.. _date-index-plots :
227237
228238Skip dates where there is no data
229- -------------------------------------
239+ ---------------------------------
230240
231241When plotting time series, eg financial time series, one often wants
232242to leave out days on which there is no data, eg weekends. By passing
@@ -263,9 +273,9 @@ to achieve the desired plot::
263273.. _point-in-poly :
264274
265275Test whether a point is inside a polygon
266- -------------------------------------------
276+ ----------------------------------------
267277
268- The :mod: `matplotlib.nxutils ` provides two high performance methods:
278+ The :mod: `~ matplotlib.nxutils ` provides two high- performance methods:
269279for a single point use :func: `~matplotlib.nxutils.pnpoly ` and for an
270280array of points use :func: `~matplotlib.nxutils.points_inside_poly `.
271281For a discussion of the implementation see `pnpoly
@@ -310,12 +320,12 @@ For a discussion of the implementation see `pnpoly
310320.. _howto-set-zorder :
311321
312322Control the depth of plot elements
313- ---------------------------------------
323+ ----------------------------------
314324
315325
316326Within an axes, the order that the various lines, markers, text,
317327collections, etc appear is determined by the
318- :meth: `matplotlib.artist.Artist.set_zorder ` property. The default
328+ :meth: `~ matplotlib.artist.Artist.set_zorder ` property. The default
319329order is patches, lines, text, with collections of lines and
320330collections of patches appearing at the same level as regular lines
321331and patches, respectively::
@@ -327,15 +337,15 @@ and patches, respectively::
327337 See :ref: `pylab_examples-zorder_demo ` for a complete example.
328338
329339You can also use the Axes property
330- :meth: `matplotlib.axes.Axes.set_axisbelow ` to control whether the grid
340+ :meth: `~ matplotlib.axes.Axes.set_axisbelow ` to control whether the grid
331341lines are placed above or below your other plot elements.
332342
333343.. _howto-axis-equal :
334344
335345Make the aspect ratio for plots equal
336- -------------------------------------------
346+ -------------------------------------
337347
338- The Axes property :meth: `matplotlib.axes.Axes.set_aspect ` controls the
348+ The Axes property :meth: `~ matplotlib.axes.Axes.set_aspect ` controls the
339349aspect ratio of the axes. You can set it to be 'auto', 'equal', or
340350some ratio which controls the ratio::
341351
@@ -351,8 +361,7 @@ some ratio which controls the ratio::
351361.. _howto-movie :
352362
353363Make a movie
354- -----------------------------------------------
355-
364+ ------------
356365
357366If you want to take an animated plot and turn it into a movie, the
358367best approach is to save a series of image files (eg PNG) and use an
@@ -392,13 +401,14 @@ a movie, and then cleans up::
392401
393402.. htmlonly ::
394403
395- Josh Lifton provided this example :ref: `animation-movie_demo `, which is possibly dated since it was written in 2004.
404+ Josh Lifton provided this example :ref: `old_animation-movie_demo `, which
405+ is possibly dated since it was written in 2004.
396406
397407
398408.. _howto-twoscale :
399409
400410Multiple y-axis scales
401- -------------------------------
411+ ----------------------
402412
403413A frequent request is to have two scales for the left and right
404414y-axis, which is possible using :func: `~matplotlib.pyplot.twinx ` (more
@@ -412,8 +422,9 @@ The approach uses :func:`~matplotlib.pyplot.twinx` (and its sister
412422turning the axes rectangular frame off on the 2nd axes to keep it from
413423obscuring the first, and manually setting the tick locs and labels as
414424desired. You can use separate matplotlib.ticker formatters and
415- locators as desired because the two axes are independent::
425+ locators as desired because the two axes are independent.
416426
427+ .. plot ::
417428 import numpy as np
418429 import matplotlib.pyplot as plt
419430
@@ -438,8 +449,8 @@ locators as desired because the two axes are independent::
438449
439450.. _howto-batch :
440451
441- Generate images without having a window popup
442- --------------------------------------------------
452+ Generate images without having a window appear
453+ ----------------------------------------------
443454
444455The easiest way to do this is use a non-interactive backend (see
445456:ref: `what-is-a-backend `) such as Agg (for PNGs), PDF, SVG or PS. In
@@ -455,9 +466,8 @@ pyplot::
455466
456467
457468.. seealso ::
458- :ref: `howto-webapp `
459- For information about running matplotlib inside of a web
460- application.
469+ :ref: `howto-webapp ` for information about running matplotlib inside
470+ of a web application.
461471
462472.. _howto-show :
463473
@@ -468,12 +478,12 @@ When you want to view your plots on your display,
468478the user interface backend will need to start the GUI mainloop.
469479This is what :func: `~matplotlib.pyplot.show ` does. It tells
470480matplotlib to raise all of the figure windows created so far and start
471- the mainloop. Because this mainloop is blocking (i.e., script execution is
472- paused), you should only call this once per script, at the end. Script
473- execution is resumed after the last window is closed. Therefore, if you are
474- using matplotlib to generate only images and do not want a user interface
475- window, you do not need to call ``show `` (see :ref: `howto-batch ` and
476- :ref: `what-is-a-backend `).
481+ the mainloop. Because this mainloop is blocking by default (i.e., script
482+ execution is paused), you should only call this once per script, at the end.
483+ Script execution is resumed after the last window is closed. Therefore, if
484+ you are using matplotlib to generate only images and do not want a user
485+ interface window, you do not need to call ``show `` (see :ref: `howto-batch `
486+ and :ref: `what-is-a-backend `).
477487
478488.. note ::
479489 Because closing a figure window invokes the destruction of its plotting
@@ -518,7 +528,6 @@ important for complex figures that take some time to draw.
518528you're all done issuing commands and you want to draw the figure now.
519529
520530.. note ::
521-
522531 :func: `~matplotlib.pyplot.show ` should typically only be called
523532 at most once per script and it should be the last line of your script.
524533 At that point, the GUI takes control of the interpreter. If you want
@@ -549,12 +558,12 @@ though we have made significant progress towards supporting blocking events.
549558.. _howto-contribute :
550559
551560Contributing: howto
552- =====================
561+ ===================
553562
554563.. _how-to-submit-patch :
555564
556565Submit a patch
557- -----------------
566+ --------------
558567
559568See :ref: `making-patches ` for information on how to make a patch with git.
560569
@@ -563,10 +572,10 @@ patch in words -- what was broken before and how you fixed it. Also,
563572even if your patch is particularly simple, just a few lines or a
564573single function replacement, we encourage people to submit git diffs
565574against HEAD of the branch they are patching. It just makes life
566- simpler for us, since we (fortunately) get a lot of contributions, and
575+ easier for us, since we (fortunately) get a lot of contributions, and
567576want to receive them in a standard format. If possible, for any
568577non-trivial change, please include a complete, free-standing example
569- that the developers can run unmodified which shows the undesired
578+ that the developers can run unmodified which shows the undesired
570579behavior pre-patch and the desired behavior post-patch, with a clear
571580verbal description of what to look for. A developer may
572581have written the function you are working on years ago, and may no
@@ -588,7 +597,7 @@ your patch abides by our coding conventions
588597.. _how-to-contribute-docs :
589598
590599Contribute to matplotlib documentation
591- -----------------------------------------
600+ --------------------------------------
592601
593602matplotlib is a big library, which is used in many ways, and the
594603documentation has only scratched the surface of everything it can
@@ -637,7 +646,7 @@ Looking for something to do? Search for `TODO <../search.html?q=todo>`_.
637646.. _howto-webapp :
638647
639648Matplotlib in a web application server
640- ====================================================
649+ ======================================
641650
642651Many users report initial problems trying to use maptlotlib in web
643652application servers, because by default matplotlib ships configured to
@@ -681,7 +690,7 @@ or by saving to a file handle::
681690 import sys
682691 fig.savefig(sys.stdout)
683692
684- Here is an example using the Python Imaging Library PIL. First the figure
693+ Here is an example using the Python Imaging Library ( PIL) . First, the figure
685694is saved to a StringIO object which is then fed to PIL for further
686695processing::
687696
@@ -693,17 +702,17 @@ processing::
693702
694703
695704matplotlib with apache
696- ------------------------------------
705+ ----------------------
697706
698707TODO; see :ref: `how-to-contribute-docs `.
699708
700709matplotlib with django
701- ------------------------------------
710+ ----------------------
702711
703712TODO; see :ref: `how-to-contribute-docs `.
704713
705714matplotlib with zope
706- ----------------------------------
715+ --------------------
707716
708717TODO; see :ref: `how-to-contribute-docs `.
709718
@@ -724,7 +733,7 @@ to these efforts that would be great.
724733.. _how-to-search-examples :
725734
726735Search examples
727- =========================================
736+ ===============
728737
729738The nearly 300 code :ref: `examples-index ` included with the matplotlib
730739source distribution are full-text searchable from the :ref: `search `
@@ -733,19 +742,15 @@ page, but sometimes when you search, you get a lot of results from the
733742in if you just want to find a complete, free-standing, working piece
734743of example code. To facilitate example searches, we have tagged every
735744code example page with the keyword ``codex `` for *code example * which
736- shouldn't appear anywhere else on this site except in the FAQ and in
737- every example. So if you want to search for an example that uses an
745+ shouldn't appear anywhere else on this site except in the FAQ.
746+ So if you want to search for an example that uses an
738747ellipse, :ref: `search ` for ``codex ellipse ``.
739748
740749
741-
742-
743-
744-
745750.. _how-to-cite-mpl :
746751
747752Cite Matplotlib
748- =================
753+ ===============
749754
750755If you want to refer to matplotlib in a publication, you can use
751756"Matplotlib: A 2D Graphics Environment" by J. D. Hunter In Computing in Science &
0 commit comments