1- **********************************
2- The matplotlib Artist API tutorial
3- **********************************
1+ ***************
2+ Artist tutorial
3+ ***************
44
55There are three layers to the matplotlib API. The FigureCanvas is the
66area onto which the figure is drawn, the Renderer is the object which
@@ -198,8 +198,8 @@ docs at http://matplotlib.sourceforge.net/classdocs.html or PDF documentation
198198at http://matplotlib.sourceforge.net/api.pdf for a listing of
199199properties for a give object.
200200
201- Getting at the objects to customize them
202- ========================================
201+ Object containers
202+ =================
203203
204204Now that we know how to inspect set the properties of a given
205205object we want to configure, we need to now how to get at that
@@ -213,8 +213,8 @@ xscale to control whether the xaxis is 'linear' or 'log'. In this
213213section we'll review where the various container objects store the
214214Artists that you want to get at.
215215
216- The Figure container
217- --------------------
216+ Figure container
217+ ----------------
218218
219219The top level container Artist is the matplotlib.figure.Figure, and it
220220contains everything in the figure. The background of the figure is a
@@ -263,9 +263,11 @@ Artist transform to fig.transFigure:
263263
264264 In [191]: fig = plt.figure()
265265
266- In [192]: l1 = matplotlib.lines.Line2D([0, 1], [0, 1], transform=fig.transFigure, figure=fig)
266+ In [192]: l1 = matplotlib.lines.Line2D([0, 1], [0, 1],
267+ transform=fig.transFigure, figure=fig)
267268
268- In [193]: l2 = matplotlib.lines.Line2D([0, 1], [1, 0], transform=fig.transFigure, figure=fig)
269+ In [193]: l2 = matplotlib.lines.Line2D([0, 1], [1, 0],
270+ transform=fig.transFigure, figure=fig)
269271
270272 In [194]: fig.lines.extend([l1, l2])
271273
@@ -290,8 +292,8 @@ texts A list Figure Text instances
290292================ ===============================================================
291293
292294
293- The Axes container
294- ------------------
295+ Axes container
296+ --------------
295297
296298The matplotlib.axes.Axes is the center of the matplotlib universe --
297299it contains the vast majority of all the Artists used in a figure with
@@ -523,46 +525,18 @@ get_minor_ticks A list of Tick instances for minor ticks
523525grid Turn the grid on or off for the major or minor ticks
524526====================== =========================================================
525527
526- Try creating the figure below
528+ Here is an example, not recommended for its beauty, which customizes
529+ the axes and tick properties
530+
531+ .. literalinclude:: figures/fig_axes_customize_simple.py
527532
528533.. image:: figures/fig_axes_customize_simple.png
529534 :scale: 75
530535
531- Exercise solution::
532-
533- import numpy as np
534- import matplotlib.pyplot as plt
535-
536- # plt.figure creates a matplotlib.figure.Figure instance
537- fig = plt.figure()
538- rect = fig.figurePatch # a rectangle instance
539- rect.set_facecolor('lightgoldenrodyellow')
540-
541- ax1 = fig.add_axes([0.1, 0.3, 0.4, 0.4])
542- rect = ax1.axesPatch
543- rect.set_facecolor('lightslategray')
544-
545-
546- for label in ax1.xaxis.get_ticklabels():
547- # label is a Text instance
548- label.set_color('red')
549- label.set_rotation(45)
550- label.set_fontsize(16)
551-
552- for line in ax1.yaxis.get_ticklines():
553- # line is a Line2D instance
554- line.set_color('green')
555- line.set_markersize(25)
556- line.set_markeredgewidth(3)
557-
558- fig.savefig('figures/fig_axes_customize_simple.png', dpi=150)
559- fig.savefig('figures/fig_axes_customize_simple.eps')
560- plt.show()
561536
562537
563-
564- The Tick containers
565- -------------------
538+ Tick containers
539+ ---------------
566540
567541The matplotlib.axis.Tick is the final container object in our descent
568542from the Figure to the Axes to the Axis to the Tick. The Tick
@@ -588,26 +562,9 @@ label2On boolean which determines whether to draw tick label
588562============== ==========================================================
589563
590564Here is an example which sets the formatter for the upper ticks with
591- dollar signs and colors them green on the right side of the yaxis::
592-
593- import numpy as np
594- import matplotlib.pyplot as plt
595- import matplotlib.ticker as ticker
596-
597- fig = plt.figure()
598- ax = fig.add_subplot(111)
599- ax.plot(100*np.random.rand(20))
600-
601- formatter = ticker.FormatStrFormatter('$%1.2f')
602- ax.yaxis.set_major_formatter(formatter)
603-
604- for tick in ax.yaxis.get_major_ticks():
605- tick.label1On = False
606- tick.label2On = True
607- tick.label2.set_color('green')
608-
609- plt.show()
565+ dollar signs and colors them green on the right side of the yaxis
610566
567+ .. literalinclude:: figures/dollar_ticks.py
611568
612569.. image:: figures/dollar_ticks.png
613570 :scale: 75
0 commit comments