From cf20c4cd8fbbea1a2c7d28c226254b086f253fdb Mon Sep 17 00:00:00 2001 From: ImportanceOfBeingErnest Date: Wed, 30 May 2018 01:57:39 +0200 Subject: [PATCH] example references for api and pyplot section --- examples/api/agg_oo_sgskip.py | 24 ++++++++- examples/api/filled_step.py | 15 ++++++ examples/api/font_file.py | 15 ++++++ examples/api/histogram_path.py | 51 +++++++++++++++++-- examples/api/image_zcoord.py | 19 ++++++- examples/api/joinstyle.py | 14 +++++ examples/api/legend.py | 16 ++++++ examples/api/line_with_text.py | 31 +++++++++-- examples/api/mathtext_asarray.py | 17 +++++++ examples/api/patch_collection.py | 23 ++++++++- examples/api/power_norm.py | 16 ++++++ examples/api/quad_bezier.py | 21 +++++++- examples/api/radar_chart.py | 21 ++++++++ examples/api/sankey_basics.py | 17 +++++++ examples/api/sankey_links.py | 18 +++++++ examples/api/sankey_rankine.py | 17 +++++++ examples/api/scatter_piecharts.py | 14 +++++ examples/api/skewt.py | 19 +++++++ examples/api/span_regions.py | 17 +++++++ examples/api/two_scales.py | 19 ++++++- examples/api/watermark_image.py | 16 ++++++ examples/api/watermark_text.py | 13 +++++ examples/axisartist/demo_parasite_axes.py | 11 ++++ examples/axisartist/demo_parasite_axes2.py | 12 ++++- examples/pyplots/align_ylabels.py | 19 +++++++ examples/pyplots/annotate_transform.py | 18 +++++++ examples/pyplots/annotation_basic.py | 16 ++++++ examples/pyplots/annotation_polar.py | 19 +++++++ examples/pyplots/auto_subplots_adjust.py | 25 +++++++++ examples/pyplots/boxplot_demo_pyplot.py | 14 +++++ examples/pyplots/compound_path_demo.py | 51 ------------------- examples/pyplots/dollar_ticks.py | 18 +++++++ examples/pyplots/fig_axes_customize_simple.py | 23 +++++++++ examples/pyplots/fig_axes_labels_simple.py | 19 +++++++ examples/pyplots/fig_x.py | 16 ++++++ examples/pyplots/pyplot_formatstr.py | 16 ++++++ examples/pyplots/pyplot_mathtext.py | 16 ++++++ examples/pyplots/pyplot_scales.py | 21 ++++++++ examples/pyplots/pyplot_simple.py | 16 ++++++ examples/pyplots/pyplot_text.py | 18 +++++++ examples/pyplots/pyplot_three.py | 15 ++++++ examples/pyplots/pyplot_two_subplots.py | 15 ++++++ examples/pyplots/text_commands.py | 20 ++++++++ examples/pyplots/text_layout.py | 15 ++++++ examples/pyplots/whats_new_1_subplot3d.py | 16 ++++++ examples/pyplots/whats_new_98_4_fancy.py | 20 ++++++++ .../pyplots/whats_new_98_4_fill_between.py | 14 +++++ examples/pyplots/whats_new_98_4_legend.py | 17 +++++++ examples/pyplots/whats_new_99_axes_grid.py | 15 ++++++ examples/pyplots/whats_new_99_mplot3d.py | 15 ++++++ examples/pyplots/whats_new_99_spines.py | 19 +++++++ .../multiple_yaxis_with_spines.py | 8 +++ 52 files changed, 905 insertions(+), 65 deletions(-) delete mode 100644 examples/pyplots/compound_path_demo.py diff --git a/examples/api/agg_oo_sgskip.py b/examples/api/agg_oo_sgskip.py index 6b4d463ddc85..9f51c22815d5 100644 --- a/examples/api/agg_oo_sgskip.py +++ b/examples/api/agg_oo_sgskip.py @@ -3,7 +3,8 @@ The object-oriented interface ============================= -A pure OO (look Ma, no pyplot!) example using the agg backend. +A pure object-oriented example using the agg backend. Notice that there is no +``pyplot`` used here. """ from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas @@ -21,3 +22,24 @@ ax.set_xlabel('time') ax.set_ylabel('volts') fig.savefig('test') + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.backends.backend_agg.FigureCanvasAgg +matplotlib.figure.Figure +matplotlib.figure.Figure.add_subplot +matplotlib.figure.Figure.savefig +matplotlib.axes.Axes.plot +matplotlib.axes.Axes.set_title +matplotlib.axes.Axes.grid +matplotlib.axes.Axes.set_xlabel +matplotlib.axes.Axes.set_ylabel diff --git a/examples/api/filled_step.py b/examples/api/filled_step.py index 48eee0c3cf4e..e885a5b21fa5 100644 --- a/examples/api/filled_step.py +++ b/examples/api/filled_step.py @@ -221,3 +221,18 @@ def stack_hist(ax, stacked_data, sty_cycle, bottoms=None, ax2.set_ylabel('x') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.fill_betweenx +matplotlib.axes.Axes.fill_between +matplotlib.axis.Axis.set_major_locator diff --git a/examples/api/font_file.py b/examples/api/font_file.py index af035bf7e95f..8dc8cddc5315 100644 --- a/examples/api/font_file.py +++ b/examples/api/font_file.py @@ -27,3 +27,18 @@ ax.set_xlabel('This is the default font') plt.show() + + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.font_manager.FontProperties +matplotlib.axes.Axes.set_title diff --git a/examples/api/histogram_path.py b/examples/api/histogram_path.py index 197706f83387..1aeefb56a97e 100644 --- a/examples/api/histogram_path.py +++ b/examples/api/histogram_path.py @@ -8,10 +8,10 @@ the faster method of using PolyCollections, were implemented before we had proper paths with moveto/lineto, closepoly etc in mpl. Now that we have them, we can draw collections of regularly shaped objects with -homogeneous properties more efficiently with a PathCollection. This -example makes a histogram -- its more work to set up the vertex arrays +homogeneous properties more efficiently with a PathCollection. This +example makes a histogram -- it's more work to set up the vertex arrays at the outset, but it should be much faster for large numbers of -objects +objects. """ import numpy as np @@ -53,3 +53,48 @@ ax.set_ylim(bottom.min(), top.max()) plt.show() + +############################################################################# +# It should be noted that instead of creating a three-dimensional array and +# using `~.path.Path.make_compound_path_from_polys`, we could as well create +# the compound path directly using vertices and codes as shown below + +nrects = len(left) +nverts = nrects*(1+3+1) +verts = np.zeros((nverts, 2)) +codes = np.ones(nverts, int) * path.Path.LINETO +codes[0::5] = path.Path.MOVETO +codes[4::5] = path.Path.CLOSEPOLY +verts[0::5,0] = left +verts[0::5,1] = bottom +verts[1::5,0] = left +verts[1::5,1] = top +verts[2::5,0] = right +verts[2::5,1] = top +verts[3::5,0] = right +verts[3::5,1] = bottom + +barpath = path.Path(verts, codes) + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.patches +matplotlib.patches.PathPatch +matplotlib.path +matplotlib.path.Path +matplotlib.path.Path.make_compound_path_from_polys +matplotlib.axes.Axes.add_patch +matplotlib.collections.PathCollection + +# This example shows an alternative to +matplotlib.collections.PolyCollection +matplotlib.axes.Axes.hist diff --git a/examples/api/image_zcoord.py b/examples/api/image_zcoord.py index d1851ccc843e..3036bd59c7d1 100644 --- a/examples/api/image_zcoord.py +++ b/examples/api/image_zcoord.py @@ -4,7 +4,10 @@ ================================== Modify the coordinate formatter to report the image "z" -value of the nearest pixel given x and y +value of the nearest pixel given x and y. +This functionality is built in by default, but it +is still useful to show how to customize the +`~.axes.Axes.format_coord` function. """ import numpy as np import matplotlib.pyplot as plt @@ -32,3 +35,17 @@ def format_coord(x, y): ax.format_coord = format_coord plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.format_coord +matplotlib.axes.Axes.imshow diff --git a/examples/api/joinstyle.py b/examples/api/joinstyle.py index 1d4562a4702d..7ac68883cfd4 100644 --- a/examples/api/joinstyle.py +++ b/examples/api/joinstyle.py @@ -31,3 +31,17 @@ def plot_angle(ax, x, y, angle, style): ax.set_xlim(-.5, 2.75) ax.set_ylim(-.5, 5.5) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.plot +matplotlib.pyplot.plot diff --git a/examples/api/legend.py b/examples/api/legend.py index 457565542a14..8a5c25a3a699 100644 --- a/examples/api/legend.py +++ b/examples/api/legend.py @@ -27,3 +27,19 @@ legend.get_frame().set_facecolor('#00FFCC') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.plot +matplotlib.pyplot.plot +matplotlib.axes.Axes.legend +matplotlib.pyplot.legend diff --git a/examples/api/line_with_text.py b/examples/api/line_with_text.py index b20d6f44f761..c876f6887948 100644 --- a/examples/api/line_with_text.py +++ b/examples/api/line_with_text.py @@ -20,7 +20,7 @@ def __init__(self, *args, **kwargs): lines.Line2D.__init__(self, *args, **kwargs) # we can't access the label attr until *after* the line is - # inited + # initiated self.text.set_text(self.get_label()) def set_figure(self, figure): @@ -59,8 +59,33 @@ def draw(self, renderer): line.text.set_color('red') line.text.set_fontsize(16) - ax.add_line(line) - plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.lines +matplotlib.lines.Line2D +matplotlib.lines.Line2D.set_data +matplotlib.artist +matplotlib.artist.Artist +matplotlib.artist.Artist.draw +matplotlib.artist.Artist.set_transform +matplotlib.text +matplotlib.text.Text +matplotlib.text.Text.set_color +matplotlib.text.Text.set_fontsize +matplotlib.text.Text.set_position +matplotlib.axes.Axes.add_line +matplotlib.transforms +matplotlib.transforms.Affine2D diff --git a/examples/api/mathtext_asarray.py b/examples/api/mathtext_asarray.py index 258ad0fa4b5e..ee107d099bf3 100644 --- a/examples/api/mathtext_asarray.py +++ b/examples/api/mathtext_asarray.py @@ -26,3 +26,20 @@ fig.figimage(rgba2, 100, 300) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.mathtext +matplotlib.mathtext.MathTextParser +matplotlib.mathtext.MathTextParser.to_png +matplotlib.mathtext.MathTextParser.to_rgba +matplotlib.figure.Figure.figimage diff --git a/examples/api/patch_collection.py b/examples/api/patch_collection.py index d3e6ec5d0556..f86d59ea65b2 100644 --- a/examples/api/patch_collection.py +++ b/examples/api/patch_collection.py @@ -3,7 +3,8 @@ Circles, Wedges and Polygons ============================ -This example demonstrates how to use patch collections. +This example demonstrates how to use +:class:`patch collections<~.collections.PatchCollection>`. """ import numpy as np @@ -56,3 +57,23 @@ fig.colorbar(p, ax=ax) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.patches +matplotlib.patches.Circle +matplotlib.patches.Wedge +matplotlib.patches.Polygon +matplotlib.collections.PatchCollection +matplotlib.collections.Collection.set_array +matplotlib.axes.Axes.add_collection +matplotlib.figure.Figure.colorbar diff --git a/examples/api/power_norm.py b/examples/api/power_norm.py index 491792c1a4b1..e22cc590e181 100644 --- a/examples/api/power_norm.py +++ b/examples/api/power_norm.py @@ -32,3 +32,19 @@ fig.tight_layout() plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.colors +matplotlib.colors.PowerNorm +matplotlib.axes.Axes.hist2d +matplotlib.pyplot.hist2d diff --git a/examples/api/quad_bezier.py b/examples/api/quad_bezier.py index 6cf190ee073a..0aacd26c55f4 100644 --- a/examples/api/quad_bezier.py +++ b/examples/api/quad_bezier.py @@ -3,8 +3,8 @@ Bezier Curve ============ -This example showcases the PathPatch object to create a Bezier polycurve path -patch. +This example showcases the `~.patches.PathPatch` object to create a Bezier +polycurve path patch. """ import matplotlib.path as mpath @@ -24,3 +24,20 @@ ax.set_title('The red point should be on the path') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.path +matplotlib.path.Path +matplotlib.patches +matplotlib.patches.PathPatch +matplotlib.axes.Axes.add_patch diff --git a/examples/api/radar_chart.py b/examples/api/radar_chart.py index c9b4c31340ef..5a1b798da274 100644 --- a/examples/api/radar_chart.py +++ b/examples/api/radar_chart.py @@ -202,3 +202,24 @@ def example_data(): size='large') plt.show() + + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.path +matplotlib.path.Path +matplotlib.spines +matplotlib.spines.Spine +matplotlib.projections +matplotlib.projections.polar +matplotlib.projections.polar.PolarAxes +matplotlib.projections.register_projection diff --git a/examples/api/sankey_basics.py b/examples/api/sankey_basics.py index d3ce6edb36df..abfd913e193b 100644 --- a/examples/api/sankey_basics.py +++ b/examples/api/sankey_basics.py @@ -99,3 +99,20 @@ # orientation and ordering of the flows is mirrored. plt.show() + + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.sankey +matplotlib.sankey.Sankey +matplotlib.sankey.Sankey.add +matplotlib.sankey.Sankey.finish diff --git a/examples/api/sankey_links.py b/examples/api/sankey_links.py index b8de4744edb3..d53d8e34b172 100644 --- a/examples/api/sankey_links.py +++ b/examples/api/sankey_links.py @@ -56,3 +56,21 @@ def corner(sankey): # accordingly. plt.show() + + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.sankey +matplotlib.sankey.Sankey +matplotlib.sankey.Sankey.add +matplotlib.sankey.Sankey.finish + diff --git a/examples/api/sankey_rankine.py b/examples/api/sankey_rankine.py index 59f1174184a6..cec4b7001f93 100644 --- a/examples/api/sankey_rankine.py +++ b/examples/api/sankey_rankine.py @@ -82,3 +82,20 @@ # must be adjusted manually, and that is a bit tricky. plt.show() + + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.sankey +matplotlib.sankey.Sankey +matplotlib.sankey.Sankey.add +matplotlib.sankey.Sankey.finish diff --git a/examples/api/scatter_piecharts.py b/examples/api/scatter_piecharts.py index 990cbe223d5a..d4ffaa34d152 100644 --- a/examples/api/scatter_piecharts.py +++ b/examples/api/scatter_piecharts.py @@ -46,3 +46,17 @@ s=s3 ** 2 * sizes, facecolor='red') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.scatter +matplotlib.pyplot.scatter diff --git a/examples/api/skewt.py b/examples/api/skewt.py index 4e0db3ce04b7..5faf0572625f 100644 --- a/examples/api/skewt.py +++ b/examples/api/skewt.py @@ -291,3 +291,22 @@ def upper_xlim(self): ax.set_xlim(-50, 50) plt.show() + + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.transforms +matplotlib.spines +matplotlib.spines.Spine +matplotlib.spines.Spine.register_axis +matplotlib.projections +matplotlib.projections.register_projection diff --git a/examples/api/span_regions.py b/examples/api/span_regions.py index 7627e96992d5..04ff7561800c 100644 --- a/examples/api/span_regions.py +++ b/examples/api/span_regions.py @@ -33,3 +33,20 @@ plt.show() + + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.collections.BrokenBarHCollection +matplotlib.collections.BrokenBarHCollection.span_where +matplotlib.axes.Axes.add_collection +matplotlib.axes.Axes.axhline diff --git a/examples/api/two_scales.py b/examples/api/two_scales.py index 8e650c6f17f8..6a0017e5b891 100644 --- a/examples/api/two_scales.py +++ b/examples/api/two_scales.py @@ -10,8 +10,8 @@ You can use separate `matplotlib.ticker` formatters and locators as desired since the two axes are independent. -Such axes are generated by calling the `Axes.twinx` method. Likewise, -`Axes.twiny` is available to generate axes that share a *y* axis but +Such axes are generated by calling the :meth:`.Axes.twinx` method. Likewise, +:meth:`.Axes.twiny` is available to generate axes that share a *y* axis but have different top and bottom scales. """ import numpy as np @@ -39,3 +39,18 @@ fig.tight_layout() # otherwise the right y-label is slightly clipped plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.twinx +matplotlib.axes.Axes.twiny +matplotlib.axes.Axes.tick_params diff --git a/examples/api/watermark_image.py b/examples/api/watermark_image.py index bd97f0e1e199..a3246e7ae0d9 100644 --- a/examples/api/watermark_image.py +++ b/examples/api/watermark_image.py @@ -26,3 +26,19 @@ fig.figimage(im, 10, 10, zorder=3) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.image +matplotlib.image.imread +matplotlib.pyplot.imread +matplotlib.figure.Figure.figimage diff --git a/examples/api/watermark_text.py b/examples/api/watermark_text.py index 258e0b3260c2..a5dbdb2ddef9 100644 --- a/examples/api/watermark_text.py +++ b/examples/api/watermark_text.py @@ -25,3 +25,16 @@ ha='right', va='bottom', alpha=0.5) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.figure.Figure.text diff --git a/examples/axisartist/demo_parasite_axes.py b/examples/axisartist/demo_parasite_axes.py index 022f195a9e3a..55c3d6e815d7 100644 --- a/examples/axisartist/demo_parasite_axes.py +++ b/examples/axisartist/demo_parasite_axes.py @@ -3,6 +3,17 @@ Demo Parasite Axes ================== +Create a parasite axes. Such axes would share the x scale with a host axes, +but show a different scale in y direction. + +Note that this approach uses the `~mpl_toolkits.axes_grid1.parasite_axes`\' +`~.mpl_toolkits.axes_grid1.parasite_axes.HostAxes` and +`~.mpl_toolkits.axes_grid1.parasite_axes.ParasiteAxes`. An alternative +approach using the :ref:`toolkit_axesgrid1-index` and +:ref:`toolkit_axisartist-index` +is found in the :doc:`/gallery/axisartist/demo_parasite_axes2` example. +An alternative approach using the usual matplotlib subplots is shown in +the :doc:`/gallery/ticks_and_spines/multiple_yaxis_with_spines` example. """ from mpl_toolkits.axisartist.parasite_axes import HostAxes, ParasiteAxes import matplotlib.pyplot as plt diff --git a/examples/axisartist/demo_parasite_axes2.py b/examples/axisartist/demo_parasite_axes2.py index bb98d040fdd0..c89614658f9b 100644 --- a/examples/axisartist/demo_parasite_axes2.py +++ b/examples/axisartist/demo_parasite_axes2.py @@ -5,12 +5,22 @@ Parasite axis demo -The following code is an example of a parasite axis. It aims to show a user how +The following code is an example of a parasite axis. It aims to show how to plot multiple different values onto one single plot. Notice how in this example, par1 and par2 are both calling twinx meaning both are tied directly to the x-axis. From there, each of those two axis can behave separately from the each other, meaning they can take on separate values from themselves as well as the x-axis. + +Note that this approach uses the `mpl_toolkits.axes_grid1.parasite_axes`\' +`~mpl_toolkits.axes_grid1.parasite_axes.host_subplot` and +`mpl_toolkits.axisartist.axislines.Axes`. An alternative approach using the +`~mpl_toolkits.axes_grid1.parasite_axes`\'s +`~.mpl_toolkits.axes_grid1.parasite_axes.HostAxes` and +`~.mpl_toolkits.axes_grid1.parasite_axes.ParasiteAxes` is the +:doc:`/gallery/axisartist/demo_parasite_axes` example. +An alternative approach using the usual matplotlib subplots is shown in +the :doc:`/gallery/ticks_and_spines/multiple_yaxis_with_spines` example. """ from mpl_toolkits.axes_grid1 import host_subplot import mpl_toolkits.axisartist as AA diff --git a/examples/pyplots/align_ylabels.py b/examples/pyplots/align_ylabels.py index 63558b0c8b45..c43f7ebe1503 100644 --- a/examples/pyplots/align_ylabels.py +++ b/examples/pyplots/align_ylabels.py @@ -3,6 +3,7 @@ Align Ylabels ============= +Align the axis labels between subplots. """ import numpy as np import matplotlib.pyplot as plt @@ -36,3 +37,21 @@ ax4.yaxis.set_label_coords(labelx, 0.5) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axis.Axis.set_label_coords +matplotlib.axes.Axes.plot +matplotlib.pyplot.plot +matplotlib.axes.Axes.set_title +matplotlib.axes.Axes.set_ylabel +matplotlib.axes.Axes.set_ylim diff --git a/examples/pyplots/annotate_transform.py b/examples/pyplots/annotate_transform.py index 458da2d1e1f1..67e7d6536289 100644 --- a/examples/pyplots/annotate_transform.py +++ b/examples/pyplots/annotate_transform.py @@ -3,6 +3,9 @@ Annotate Transform ================== +This example shows how to use different coordinate systems for annotations. +For a complete overview of the annotation capabilities, also see the +:doc:`annotation tutorial`. """ import numpy as np import matplotlib.pyplot as plt @@ -38,3 +41,18 @@ plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.transforms.Transform.transform_point +matplotlib.axes.Axes.annotate +matplotlib.pyplot.annotate diff --git a/examples/pyplots/annotation_basic.py b/examples/pyplots/annotation_basic.py index c1ad76dbcc2f..1b2e6ec1a09c 100644 --- a/examples/pyplots/annotation_basic.py +++ b/examples/pyplots/annotation_basic.py @@ -6,6 +6,8 @@ This example shows how to annotate a plot with an arrow pointing to provided coordinates. We modify the defaults of the arrow, to "shrink" it. +For a complete overview of the annotation capabilities, also see the +:doc:`annotation tutorial`. """ import numpy as np import matplotlib.pyplot as plt @@ -21,3 +23,17 @@ ) ax.set_ylim(-2, 2) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.annotate +matplotlib.pyplot.annotate diff --git a/examples/pyplots/annotation_polar.py b/examples/pyplots/annotation_polar.py index 129291aae167..e900c70d102d 100644 --- a/examples/pyplots/annotation_polar.py +++ b/examples/pyplots/annotation_polar.py @@ -3,6 +3,10 @@ Annotation Polar ================ +This example shows how to create an annotation on a polar graph. + +For a complete overview of the annotation capabilities, also see the +:doc:`annotation tutorial`. """ import numpy as np import matplotlib.pyplot as plt @@ -25,3 +29,18 @@ verticalalignment='bottom', ) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.projections.polar +matplotlib.axes.Axes.annotate +matplotlib.pyplot.annotate diff --git a/examples/pyplots/auto_subplots_adjust.py b/examples/pyplots/auto_subplots_adjust.py index bb430827bef3..7b13cda9e90b 100644 --- a/examples/pyplots/auto_subplots_adjust.py +++ b/examples/pyplots/auto_subplots_adjust.py @@ -3,6 +3,13 @@ Auto Subplots Adjust ==================== +Automatically adjust subplot parameters. This example shows a way to determine +a subplot parameter from the extent of the ticklabels using a callback on the +:doc:`draw_event`. + +Note that a similar result would be achieved using `~.Figure.tight_layout` +or `~.Figure.contrained_layout`; this example shows how one could customize +the subplot parameter adjustment. """ import matplotlib.pyplot as plt import matplotlib.transforms as mtransforms @@ -34,3 +41,21 @@ def on_draw(event): plt.show() +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.artist.Artist.get_window_extent +matplotlib.transforms.Bbox +matplotlib.transforms.Bbox.inverse_transformed +matplotlib.transforms.Bbox.union +matplotlib.figure.Figure.subplots_adjust +matplotlib.figure.SubplotParams +matplotlib.backend_bases.FigureCanvasBase.mpl_connect diff --git a/examples/pyplots/boxplot_demo_pyplot.py b/examples/pyplots/boxplot_demo_pyplot.py index 90eabd9e567c..26e4fcd9b72b 100644 --- a/examples/pyplots/boxplot_demo_pyplot.py +++ b/examples/pyplots/boxplot_demo_pyplot.py @@ -80,3 +80,17 @@ ax7.boxplot(data) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.boxplot +matplotlib.pyplot.boxplot diff --git a/examples/pyplots/compound_path_demo.py b/examples/pyplots/compound_path_demo.py deleted file mode 100644 index 6310cf8b021f..000000000000 --- a/examples/pyplots/compound_path_demo.py +++ /dev/null @@ -1,51 +0,0 @@ -""" -================== -Compound Path Demo -================== - -""" -import numpy as np - -import matplotlib.pyplot as plt -import matplotlib.patches as patches -import matplotlib.path as path - -fig = plt.figure() -ax = fig.add_subplot(111) - -# Fixing random state for reproducibility -np.random.seed(19680801) - -# histogram our data with numpy -data = np.random.randn(1000) -n, bins = np.histogram(data, 100) - -# get the corners of the rectangles for the histogram -left = np.array(bins[:-1]) -right = np.array(bins[1:]) -bottom = np.zeros(len(left)) -top = bottom + n -nrects = len(left) - -nverts = nrects*(1+3+1) -verts = np.zeros((nverts, 2)) -codes = np.ones(nverts, int) * path.Path.LINETO -codes[0::5] = path.Path.MOVETO -codes[4::5] = path.Path.CLOSEPOLY -verts[0::5,0] = left -verts[0::5,1] = bottom -verts[1::5,0] = left -verts[1::5,1] = top -verts[2::5,0] = right -verts[2::5,1] = top -verts[3::5,0] = right -verts[3::5,1] = bottom - -barpath = path.Path(verts, codes) -patch = patches.PathPatch(barpath, facecolor='green', edgecolor='yellow', alpha=0.5) -ax.add_patch(patch) - -ax.set_xlim(left[0], right[-1]) -ax.set_ylim(bottom.min(), top.max()) - -plt.show() diff --git a/examples/pyplots/dollar_ticks.py b/examples/pyplots/dollar_ticks.py index 2f8c864e977c..e980de104848 100644 --- a/examples/pyplots/dollar_ticks.py +++ b/examples/pyplots/dollar_ticks.py @@ -3,6 +3,7 @@ Dollar Ticks ============ +Use a `~.ticker.FormatStrFormatter` to prepend dollar signs on y axis labels. """ import numpy as np import matplotlib.pyplot as plt @@ -23,3 +24,20 @@ tick.label2.set_color('green') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.ticker +matplotlib.ticker.FormatStrFormatter +matplotlib.axis.Axis.set_major_formatter +matplotlib.axis.Axis.get_major_ticks +matplotlib.axis.Tick diff --git a/examples/pyplots/fig_axes_customize_simple.py b/examples/pyplots/fig_axes_customize_simple.py index 0152be313c4e..50c2411bfcb8 100644 --- a/examples/pyplots/fig_axes_customize_simple.py +++ b/examples/pyplots/fig_axes_customize_simple.py @@ -3,6 +3,7 @@ Fig Axes Customize Simple ========================= +Customize the background, labels and ticks of a simple plot. """ import numpy as np import matplotlib.pyplot as plt @@ -32,3 +33,25 @@ line.set_markeredgewidth(3) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axis.Axis.get_ticklabels +matplotlib.axis.Axis.get_ticklines +matplotlib.text.Text.set_rotation +matplotlib.text.Text.set_fontsize +matplotlib.text.Text.set_color +matplotlib.lines.Line2D +matplotlib.lines.Line2D.set_color +matplotlib.lines.Line2D.set_markersize +matplotlib.lines.Line2D.set_markeredgewidth +matplotlib.patches.Patch.set_facecolor diff --git a/examples/pyplots/fig_axes_labels_simple.py b/examples/pyplots/fig_axes_labels_simple.py index b36967912c89..2d8e6a14a9b8 100644 --- a/examples/pyplots/fig_axes_labels_simple.py +++ b/examples/pyplots/fig_axes_labels_simple.py @@ -3,6 +3,7 @@ Fig Axes Labels Simple ====================== +Label the axes of a plot. """ import numpy as np import matplotlib.pyplot as plt @@ -26,3 +27,21 @@ ax2.set_xlabel('time (s)') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.set_xlabel +matplotlib.axes.Axes.set_ylabel +matplotlib.axes.Axes.set_title +matplotlib.axes.Axes.plot +matplotlib.axes.Axes.hist +matplotlib.figure.Figure.add_axes diff --git a/examples/pyplots/fig_x.py b/examples/pyplots/fig_x.py index ecd28e2f5740..4e5d120a9a9b 100644 --- a/examples/pyplots/fig_x.py +++ b/examples/pyplots/fig_x.py @@ -3,6 +3,7 @@ Fig X ===== +Add lines to a figure (without axes). """ import numpy as np import matplotlib.pyplot as plt @@ -18,3 +19,18 @@ fig.lines.extend([l1, l2]) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.pyplot.figure +matplotlib.lines +matplotlib.lines.Line2D diff --git a/examples/pyplots/pyplot_formatstr.py b/examples/pyplots/pyplot_formatstr.py index e558fb4f35ca..057cba15b92f 100644 --- a/examples/pyplots/pyplot_formatstr.py +++ b/examples/pyplots/pyplot_formatstr.py @@ -3,8 +3,24 @@ Pyplot Formatstr ================ +Use a format string to colorize a `~matplotlib.axes.Axes.plot` and set its +markers. """ import matplotlib.pyplot as plt plt.plot([1,2,3,4], [1,4,9,16], 'ro') plt.axis([0, 6, 0, 20]) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.pyplot.plot +matplotlib.axes.Axes.plot diff --git a/examples/pyplots/pyplot_mathtext.py b/examples/pyplots/pyplot_mathtext.py index 4924b1a4665d..709488bcc933 100644 --- a/examples/pyplots/pyplot_mathtext.py +++ b/examples/pyplots/pyplot_mathtext.py @@ -3,6 +3,8 @@ Pyplot Mathtext =============== +Use mathematical expressions in text labels. For an overview over MathText +see :doc:`/tutorials/text/mathtext`. """ import numpy as np import matplotlib.pyplot as plt @@ -17,3 +19,17 @@ plt.xlabel('time (s)') plt.ylabel('volts (mV)') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.pyplot.text +matplotlib.axes.Axes.text diff --git a/examples/pyplots/pyplot_scales.py b/examples/pyplots/pyplot_scales.py index 944f339e83b7..910d11323dbe 100644 --- a/examples/pyplots/pyplot_scales.py +++ b/examples/pyplots/pyplot_scales.py @@ -3,6 +3,9 @@ Pyplot Scales ============= +Create plots on different scales. Here a linear, a logarithmic, a symmetric +logarithmic and a logit scale are shown. For further examples also see the +:ref:`scales_examples` section of the gallery. """ import numpy as np import matplotlib.pyplot as plt @@ -59,3 +62,21 @@ wspace=0.35) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.pyplot.subplot +matplotlib.pyplot.subplots_adjust +matplotlib.pyplot.gca +matplotlib.pyplot.yscale +matplotlib.ticker.NullFormatter +matplotlib.axis.Axis.set_minor_formatter diff --git a/examples/pyplots/pyplot_simple.py b/examples/pyplots/pyplot_simple.py index c97c40d6a143..6ad0483ebe2e 100644 --- a/examples/pyplots/pyplot_simple.py +++ b/examples/pyplots/pyplot_simple.py @@ -3,8 +3,24 @@ Pyplot Simple ============= +A most simple plot, where a list of numbers is plotted against their index. """ import matplotlib.pyplot as plt plt.plot([1,2,3,4]) plt.ylabel('some numbers') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.pyplot.plot +matplotlib.pyplot.ylabel +matplotlib.pyplot.show diff --git a/examples/pyplots/pyplot_text.py b/examples/pyplots/pyplot_text.py index b070e06595e6..4492ce438c01 100644 --- a/examples/pyplots/pyplot_text.py +++ b/examples/pyplots/pyplot_text.py @@ -24,3 +24,21 @@ plt.axis([40, 160, 0, 0.03]) plt.grid(True) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.pyplot.hist +matplotlib.pyplot.xlabel +matplotlib.pyplot.ylabel +matplotlib.pyplot.text +matplotlib.pyplot.grid +matplotlib.pyplot.show diff --git a/examples/pyplots/pyplot_three.py b/examples/pyplots/pyplot_three.py index 8576b36802b1..9026e4acae1f 100644 --- a/examples/pyplots/pyplot_three.py +++ b/examples/pyplots/pyplot_three.py @@ -3,6 +3,7 @@ Pyplot Three ============ +Plot three line plots in a single call to `~matplotlib.pyplot.plot`. """ import numpy as np import matplotlib.pyplot as plt @@ -13,3 +14,17 @@ # red dashes, blue squares and green triangles plt.plot(t, t, 'r--', t, t**2, 'bs', t, t**3, 'g^') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.pyplot.plot +matplotlib.axes.Axes.plot diff --git a/examples/pyplots/pyplot_two_subplots.py b/examples/pyplots/pyplot_two_subplots.py index dbc64d628b5d..964e1fdfd6e7 100644 --- a/examples/pyplots/pyplot_two_subplots.py +++ b/examples/pyplots/pyplot_two_subplots.py @@ -3,6 +3,7 @@ Pyplot Two Subplots =================== +Create a figure with two subplots with `pyplot.subplot`. """ import numpy as np import matplotlib.pyplot as plt @@ -20,3 +21,17 @@ def f(t): plt.subplot(212) plt.plot(t2, np.cos(2*np.pi*t2), 'r--') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.pyplot.figure +matplotlib.pyplot.subplot diff --git a/examples/pyplots/text_commands.py b/examples/pyplots/text_commands.py index 4885a0051925..d7df2ecfca3d 100644 --- a/examples/pyplots/text_commands.py +++ b/examples/pyplots/text_commands.py @@ -38,3 +38,23 @@ ax.axis([0, 10, 0, 10]) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.figure.Figure.suptitle +matplotlib.figure.Figure.add_subplot +matplotlib.figure.Figure.subplots_adjust +matplotlib.axes.Axes.set_title +matplotlib.axes.Axes.set_xlabel +matplotlib.axes.Axes.set_ylabel +matplotlib.axes.Axes.text +matplotlib.axes.Axes.annotate diff --git a/examples/pyplots/text_layout.py b/examples/pyplots/text_layout.py index 48ea9a4a5676..4e28cf98904c 100644 --- a/examples/pyplots/text_layout.py +++ b/examples/pyplots/text_layout.py @@ -3,6 +3,7 @@ Text Layout =========== +Create text with different alignment and rotation. """ import matplotlib.pyplot as plt import matplotlib.patches as patches @@ -81,3 +82,17 @@ ax.set_axis_off() plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.text +matplotlib.pyplot.text diff --git a/examples/pyplots/whats_new_1_subplot3d.py b/examples/pyplots/whats_new_1_subplot3d.py index 7b4bd33a8ed8..5372ad10e0f1 100644 --- a/examples/pyplots/whats_new_1_subplot3d.py +++ b/examples/pyplots/whats_new_1_subplot3d.py @@ -3,6 +3,7 @@ Whats New 1 Subplot3d ===================== +Create two three-dimensional plots in the same figure. """ from mpl_toolkits.mplot3d.axes3d import Axes3D from matplotlib import cm @@ -34,3 +35,18 @@ plt.show() +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib, mpl_toolkits +matplotlib.figure.Figure.add_subplot +mpl_toolkits.mplot3d.axes3d.Axes3D.plot_surface +mpl_toolkits.mplot3d.axes3d.Axes3D.plot_wireframe +mpl_toolkits.mplot3d.axes3d.Axes3D.set_zlim3d diff --git a/examples/pyplots/whats_new_98_4_fancy.py b/examples/pyplots/whats_new_98_4_fancy.py index 24691a8abbb6..b8c1d2fbdf90 100644 --- a/examples/pyplots/whats_new_98_4_fancy.py +++ b/examples/pyplots/whats_new_98_4_fancy.py @@ -3,6 +3,7 @@ Whats New 0.98.4 Fancy ====================== +Create fancy box and arrow styles. """ import matplotlib.patches as mpatch import matplotlib.pyplot as plt @@ -58,3 +59,22 @@ def make_arrowstyles(ax): plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.patches +matplotlib.patches.BoxStyle +matplotlib.patches.BoxStyle.get_styles +matplotlib.patches.ArrowStyle +matplotlib.patches.ArrowStyle.get_styles +matplotlib.axes.Axes.text +matplotlib.axes.Axes.annotate diff --git a/examples/pyplots/whats_new_98_4_fill_between.py b/examples/pyplots/whats_new_98_4_fill_between.py index 0fbd6bd271d9..8719a5428e03 100644 --- a/examples/pyplots/whats_new_98_4_fill_between.py +++ b/examples/pyplots/whats_new_98_4_fill_between.py @@ -3,6 +3,7 @@ Fill Between ============ +Fill the area between two curves. """ import matplotlib.pyplot as plt import numpy as np @@ -18,3 +19,16 @@ ax.set_title('Fill Between') plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.fill_between diff --git a/examples/pyplots/whats_new_98_4_legend.py b/examples/pyplots/whats_new_98_4_legend.py index c60d91588cb0..ed534ca18992 100644 --- a/examples/pyplots/whats_new_98_4_legend.py +++ b/examples/pyplots/whats_new_98_4_legend.py @@ -3,6 +3,7 @@ Whats New 0.98.4 Legend ======================= +Create a legend and tweak it with a shadow and a box. """ import matplotlib.pyplot as plt import numpy as np @@ -18,3 +19,19 @@ plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axes.Axes.legend +matplotlib.pyplot.legend +matplotlib.legend.Legend +matplotlib.legend.Legend.get_frame diff --git a/examples/pyplots/whats_new_99_axes_grid.py b/examples/pyplots/whats_new_99_axes_grid.py index 73c75daf5798..a13bcce2e2f5 100644 --- a/examples/pyplots/whats_new_99_axes_grid.py +++ b/examples/pyplots/whats_new_99_axes_grid.py @@ -3,6 +3,7 @@ Whats New 0.99 Axes Grid ======================== +Create RGB composite images. """ import numpy as np import matplotlib.pyplot as plt @@ -50,3 +51,17 @@ def get_rgb(): plt.draw() plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import mpl_toolkits +mpl_toolkits.axes_grid1.axes_rgb.RGBAxes +mpl_toolkits.axes_grid1.axes_rgb.RGBAxes.imshow_rgb diff --git a/examples/pyplots/whats_new_99_mplot3d.py b/examples/pyplots/whats_new_99_mplot3d.py index f3037740e2e1..6a85c0a383c4 100644 --- a/examples/pyplots/whats_new_99_mplot3d.py +++ b/examples/pyplots/whats_new_99_mplot3d.py @@ -3,6 +3,7 @@ Whats New 0.99 Mplot3d ====================== +Create a 3D surface plot. """ import numpy as np import matplotlib.pyplot as plt @@ -20,3 +21,17 @@ ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.viridis) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import mpl_toolkits +mpl_toolkits.mplot3d.Axes3D +mpl_toolkits.mplot3d.Axes3D.plot_surface diff --git a/examples/pyplots/whats_new_99_spines.py b/examples/pyplots/whats_new_99_spines.py index 4d0d5bc09f74..1c8461497a98 100644 --- a/examples/pyplots/whats_new_99_spines.py +++ b/examples/pyplots/whats_new_99_spines.py @@ -50,3 +50,22 @@ def adjust_spines(ax,spines): adjust_spines(ax,['bottom']) plt.show() + +############################################################################# +# +# ------------ +# +# References +# """""""""" +# +# The use of the following functions, methods, classes and modules is shown +# in this example: + +import matplotlib +matplotlib.axis.Axis.set_ticks +matplotlib.axis.XAxis.set_ticks_position +matplotlib.axis.YAxis.set_ticks_position +matplotlib.spines +matplotlib.spines.Spine +matplotlib.spines.Spine.set_color +matplotlib.spines.Spine.set_position diff --git a/examples/ticks_and_spines/multiple_yaxis_with_spines.py b/examples/ticks_and_spines/multiple_yaxis_with_spines.py index 02320dec5b8b..19d41f49c212 100644 --- a/examples/ticks_and_spines/multiple_yaxis_with_spines.py +++ b/examples/ticks_and_spines/multiple_yaxis_with_spines.py @@ -3,6 +3,14 @@ Multiple Yaxis With Spines ========================== +Create multiple y axes with a shared x axis. This is done by creating +a `~.axes.Axes.twinx` axes, turning all spines but the right one invisible +and offset its position using `~.spines.Spine.set_position`. + +Note that this approach uses `matplotlib.axes.Axes` and their +:class:`Spines<~matplotlib.spines.Spine>`. An alternative approach for parasite +axes is shown in the :doc:`/gallery/axisartist/demo_parasite_axes` and +:doc:`/gallery/axisartist/demo_parasite_axes2` examples. """ import matplotlib.pyplot as plt