5
5
6
6
Using Artist objects to render on the canvas.
7
7
8
- There are three layers to the matplotlib API.
8
+ There are three layers to the Matplotlib API.
9
9
10
10
* the :class:`matplotlib.backend_bases.FigureCanvas` is the area onto which
11
11
the figure is drawn
12
- * the :class:`matplotlib.backend_bases.Renderer` is
13
- the object which knows how to draw on the
14
- :class:`~matplotlib.backend_bases.Figu
10000
reCanvas`
12
+ * the :class:`matplotlib.backend_bases.Renderer` is the object which knows how
13
+ to draw on the :class:`~matplotlib.backend_bases.FigureCanvas`
15
14
* and the :class:`matplotlib.artist.Artist` is the object that knows how to use
16
15
a renderer to paint onto the canvas.
17
16
47
46
ax = fig.add_subplot(2, 1, 1) # two rows, one column, first plot
48
47
49
48
The :class:`~matplotlib.axes.Axes` is probably the most important
50
- class in the matplotlib API, and the one you will be working with most
49
+ class in the Matplotlib API, and the one you will be working with most
51
50
of the time. This is because the ``Axes`` is the plotting area into
52
51
which most of the objects go, and the ``Axes`` has many special helper
53
52
methods (:meth:`~matplotlib.axes.Axes.plot`,
@@ -83,8 +82,8 @@ class in the matplotlib API, and the one you will be working with most
83
82
``fig.add_subplot`` call above (remember ``Subplot`` is just a
84
83
subclass of ``Axes``) and when you call ``ax.plot``, it creates a
85
84
``Line2D`` instance and adds it to the :attr:`Axes.lines
86
- <matplotlib.axes.Axes.lines>` list. In the interactive `ipython
87
- <http ://ipython.org/>`_ session below, you can see that the
85
+ <matplotlib.axes.Axes.lines>` list. In the interactive `IPython
86
+ <https ://ipython.org/>`_ session below, you can see that the
88
87
``Axes.lines`` list is length one and contains the same line that was
89
88
returned by the ``line, = ax.plot...`` call:
90
89
@@ -170,7 +169,7 @@ class in the matplotlib API, and the one you will be working with most
170
169
# ========== =================================================================
171
170
# alpha The transparency - a scalar from 0-1
172
171
# animated A boolean that is used to facilitate animated drawing
173
- # axes The axes that the Artist lives in, possibly None
172
+ # axes The Axes that the Artist lives in, possibly None
174
173
# clip_box The bounding box that clips the Artist
175
174
# clip_on Whether clipping is enabled
176
175
# clip_path The path the artist is clipped to
@@ -183,7 +182,7 @@ class in the matplotlib API, and the one you will be working with most
183
182
# visible A boolean whether the artist should be drawn
184
183
# zorder A number which determines the drawing order
185
184
# rasterized Boolean; Turns vectors into raster graphics (for compression &
186
- # eps transparency)
185
+ # EPS transparency)
187
186
# ========== =================================================================
188
187
#
189
188
# Each of the properties is accessed with an old-fashioned setter or
@@ -307,33 +306,33 @@ class in the matplotlib API, and the one you will be working with most
307
306
# In [160]: print(fig.axes)
308
307
# [<AxesSubplot:>, <matplotlib.axes._axes.Axes object at 0x7f0768702be0>]
309
308
#
310
- # Because the figure maintains the concept of the "current axes " (see
309
+ # Because the figure maintains the concept of the "current Axes " (see
311
310
# :meth:`Figure.gca <matplotlib.figure.Figure.gca>` and
312
311
# :meth:`Figure.sca <matplotlib.figure.Figure.sca>`) to support the
313
- # pylab/pyplot state machine, you should not insert or remove axes
314
- # directly from the axes list, but rather use the
312
+ # pylab/pyplot state machine, you should not insert or remove Axes
313
+ # directly from the Axes list, but rather use the
315
314
# :meth:`~matplotlib.figure.Figure.add_subplot` and
316
315
# :meth:`~matplotlib.figure.Figure.add_axes` methods to insert, and the
317
316
# :meth:`~matplotlib.figure.Figure.delaxes` method to delete. You are
318
- # free however, to iterate over the list of axes or index into it to get
317
+ # free however, to iterate over the list of Axes or index into it to get
319
318
# access to ``Axes`` instances you want to customize. Here is an
320
- # example which turns all the axes grids on::
319
+ # example which turns all the Axes grids on::
321
320
#
322
321
# for ax in fig.axes:
323
322
# ax.grid(True)
324
323
#
325
324
#
326
- # The figure also has its own text, lines, patches and images, which you
327
- # can use to add primitives directly. The default coordinate system for
328
- # the ``Figure`` will simply be in pixels (which is not usually what you
329
- # want) but you can control this by setting the transform property of
330
- # the ``Artist`` you are adding to the figure.
325
+ # The figure also has its own ``images``, ``lines``, ``patches`` and ``text``
326
+ # attributes, which you can use to add primitives directly. When doing so, the
327
+ # default coordinate system for the ``Figure`` will simply be in pixels (which
328
+ # is not usually what you want). If you instead use Figure-level methods to add
329
+ # Artists (e.g., using `.Figure.text` to add text), then the default coordinate
330
+ # system will be "figure coordinates" where (0, 0) is the bottom-left of the
331
+ # figure and (1, 1) is the top-right of the figure.
331
332
#
332
- # .. TODO: Is that still true?
333
- #
334
- # More useful is "figure coordinates" where (0, 0) is the bottom-left of
335
- # the figure and (1, 1) is the top-right of the figure which you can
336
- # obtain by setting the ``Artist`` transform to :attr:`fig.transFigure
333
+ # As with all ``Artist``\s, you can control this coordinate system by setting
334
+ # the transform property. You can explicitly use "figure coordinates" by
335
+ # setting the ``Artist`` transform to :attr:`fig.transFigure
337
336
# <matplotlib.figure.Figure.transFigure>`:
338
337
339
338
import<
F438
/span> matplotlib .lines as lines
@@ -347,23 +346,22 @@ class in the matplotlib API, and the one you will be working with most
347
346
plt .show ()
348
347
349
348
###############################################################################
350
- # Here is a summary of the Artists the figure contains
351
- #
352
- # .. TODO: Add xrefs to this table
349
+ # Here is a summary of the Artists the Figure contains
353
350
#
354
351
# ================ ============================================================
355
352
# Figure attribute Description
356
353
# ================ ============================================================
357
- # axes A list of Axes instances (includes Subplot)
358
- # patch The Rectangle background
359
- # images A list of FigureImage patches -
354
+ # axes A list of `~.axes. Axes` instances (includes Subplot)
355
+ # patch The `. Rectangle` background
356
+ # images A list of `. FigureImage` patches -
360
357
# useful for raw pixel display
361
- # legends A list of Figure Legend instances
362
- # (different from Axes.legends)
363
- # lines A list of Figure Line2D instances
364
- # (rarely used, see Axes.lines)
365
- # patches A list of Figure patches (rarely used, see Axes.patches)
366
- # texts A list Figure Text instances
358
+ # legends A list of Figure `.Legend` instances
359
+ # (different from ``Axes.legends``)
360
+ # lines A list of Figure `.Line2D` instances
361
+ # (rarely used, see ``Axes.lines``)
362
+ # patches A list of Figure `.Patch`\s
363
+ # (rarely used, see ``Axes.patches``)
364
+ # texts A list Figure `.Text` instances
367
365
# ================ ============================================================
368
366
#
369
367
# .. _axes-container:
@@ -538,20 +536,21 @@ class in the matplotlib API, and the one you will be working with most
538
536
# below summarizes a small sampling of them, the kinds of ``Artist`` they
539
537
# create, and where they store them
540
538
#
541
- # ============================== ==================== =======================
542
- # Helper method Artist Container
543
- # ============================== ==================== =======================
544
- # ax.annotate - text annotations Annotate ax.texts
545
- # ax.bar - bar charts Rectangle ax.patches
546
- # ax.errorbar - error bar plots Line2D and Rectangle ax.lines and ax.patches
547
- # ax.fill - shared area Polygon ax.patches
548
- # ax.hist - histograms Rectangle ax.patches
549
- # ax.imshow - image data AxesImage ax.images
550
- # ax.legend - axes legends Legend ax.legends
551
- # ax.plot - xy plots Line2D ax.lines
552
- # ax.scatter - scatter charts PolygonCollection ax.collections
553
- # ax.text - text Text ax.texts
554
- # ============================== ==================== =======================
539
+ # ========================================= ================= ===============
540
+ # Axes helper method Artist Container
541
+ # ========================================= ================= ===============
542
+ # `~.axes.Axes.annotate` - text annotations `.Annotation` ax.texts
543
+ # `~.axes.Axes.bar` - bar charts `.Rectangle` ax.patches
544
+ # `~.axes.Axes.errorbar` - error bar plots `.Line2D` and ax.lines and
545
+ # `.Rectangle` ax.patches
546
+ # `~.axes.Axes.fill` - shared area `.Polygon` ax.patches
547
+ # `~.axes.Axes.hist` - histograms `.Rectangle` ax.patches
548
+ # `~.axes.Axes.imshow` - image data `.AxesImage` ax.images
549
+ # `~.axes.Axes.legend` - Axes legends `.Legend` ax.legends
550
+ # `~.axes.Axes.plot` - xy plots `.Line2D` ax.lines
551
+ # `~.axes.Axes.scatter` - scatter charts `.PolyCollection` ax.collections
552
+ # `~.axes.Axes.text` - text `.Text` ax.texts
553
+ # ========================================= ================= ===============
555
554
#
556
555
#
557
556
# In addition to all of these ``Artists``, the ``Axes`` contains two
@@ -572,20 +571,20 @@ class in the matplotlib API, and the one you will be working with most
572
571
#
573
572
# Below is a summary of the Artists that the Axes contains
574
573
#
575
- # ============== ======================================
574
+ # ============== =========================================
576
575
# Axes attribute Description
577
- # ============== ======================================
578
- # artists A list of Artist instances
579
- # patch Rectangle instance for Axes background
580
- # collections A list of Collection instances
581
- # images A list of AxesImage
582
- # legends A list of Legend instances
583
- # lines A list of Line2D instances
584
- # patches A list of Patch instances
585
- # texts A list of Text instances
586
- # xaxis matplotlib.axis.XAxis instance
587
- # yaxis matplotlib.axis.YAxis instance
588
- # ============== ======================================
576
+ # ============== =========================================
577
+ # artists A list of `. Artist` instances
578
+ # patch `. Rectangle` instance for Axes background
579
+ # collections A list of `. Collection` instances
580
+ # images A list of `. AxesImage`
581
+ # legends A list of `. Legend` instances
582
+ # lines A list of `. Line2D` instances
583
+ # patches A list of `. Patch` instances
584
+ # texts A list of `. Text` instances
585
+ # xaxis A ` matplotlib.axis.XAxis` instance
586
+ # yaxis A ` matplotlib.axis.YAxis` instance
587
+ # ============== =========================================
589
588
#
590
589
# .. _axis-container:
591
590
#
@@ -640,28 +639,35 @@ class in the matplotlib API, and the one you will be working with most
640
639
# (these have corresponding setters where useful, such as
641
640
# :meth:`~matplotlib.axis.Axis.set_major_formatter`.)
642
641
#
643
- # ==================== =====================================================
644
- # Accessor method Description
645
- # ==================== =====================================================
646
- # get_scale The scale of the axis, e.g., 'log' or 'linear'
647
- # get_view_interval The interval instance of the axis view limits
648
- # get_data_interval The interval instance of the axis data limits
649
- # get_gridlines A list of grid lines for the Axis
650
- # get_label The axis label - a Text instance
651
- # get_ticklabels A list of Text instances - keyword minor=True|False
652
- # get_ticklines A list of Line2D instances - keyword minor=True|False
653
- # get_ticklocs A list of Tick locations - keyword minor=True|False
654
- # get_major_locator The `.ticker.Locator` instance for major ticks
655
- # get_major_formatter The `.ticker.Formatter` instance for major ticks
656
- # get_minor_locator The `.ticker.Locator` instance for minor ticks
657
- # get_minor_formatter The `.ticker.Formatter` instance for minor ticks
658
- # get_major_ticks A list of Tick instances for major ticks
659
- # get_minor_ticks A list of Tick instances for minor ticks
660
- # grid Turn the grid on or off for the major or minor ticks
661
- # ==================== =====================================================
642
+ # ============================= ==============================================
643
+ # Axis accessor method Description
644
+ # ============================= ==============================================
645
+ # `~.Axis.get_scale` The scale of the Axis, e.g., 'log' or 'linear'
646
+ # `~.Axis.get_view_interval` The interval instance of the Axis view limits
647
+ # `~.Axis.get_data_interval` The interval instance of the Axis data limits
648
+ # `~.Axis.get_gridlines` A list of grid lines for the Axis
649
+ # `~.Axis.get_label` The Axis label - a `.Text` instance
650
+ # `~.Axis.get_offset_text` The Axis offset text - a `.Text` instance
651
+ # `~.Axis.get_ticklabels` A list of `.Text` instances -
652
+ # keyword minor=True|False
653
+ # `~.Axis.get_ticklines` A list of `.Line2D` instances -
654
+ # keyword minor=True|False
655
+ # `~.Axis.get_ticklocs` A list of Tick locations -
656
+ # keyword minor=True|False
657
+ # `~.Axis.get_major_locator` The `.ticker.Locator` instance for major ticks
658
+ # `~.Axis.get_major_formatter` The `.ticker.Formatter` instance for major
659
+ # ticks
660
+ # `~.Axis.get_minor_locator` The `.ticker.Locator` instance for minor ticks
661
+ # `~.Axis.get_minor_formatter` The `.ticker.Formatter` instance for minor
662
+ # ticks
663
+ # `~.axis.Axis.get_major_ticks` A list of `.Tick` instances for major ticks
664
+ # `~.axis.Axis.get_minor_ticks` A list of `.Tick` instances for minor ticks
665
+ # `~.Axis.grid` Turn the grid on or off for the major or minor
666
+ # ticks
667
+ # ============================= ==============================================
662
668
#
663
669
# Here is an example, not recommended for its beauty, which customizes
664
- # the axes and tick properties
670
+ # the Axes and Tick properties.
665
671
666
672
# plt.figure creates a matplotlib.figure.Figure instance
667
673
fig = plt .figure ()
@@ -701,15 +707,15 @@ class in the matplotlib API, and the one you will be working with most
701
707
# and lower ticks. Each of these is accessible directly as an attribute
702
708
# of the ``Tick``.
703
709
#
704
- # ============== ==========================================================
705
- # Tick attribute Description
706
- # ============== ==========================================================
707
- # tick1line Line2D instance
708
- # tick2line Line2D instance
709
- # gridline Line2D instance
710
- # label1 Text instance
711
- # label2 Text instance
712
- # ============== ==========================================================
710
+ # ============== ==========================================================
711 + # Tick attribute Description
712
+ # ============== ==========================================================
713
+ # tick1line A `. Line2D` instance
714
+ # tick2line A `. Line2D` instance
715
+ # gridline A `. Line2D` instance
716
+ # label1 A `. Text` instance
717
+ # label2 A `. Text` instance
718
+ # ============== ==========================================================
713
719
#
714
720
# Here is an example which sets the formatter for the right side ticks with
715
721
# dollar signs and colors them green on the right side of the yaxis.
0 commit comments