From 4c9c41f04d3ad3e1ad0fa15dbe9b6465671d0eaa Mon Sep 17 00:00:00 2001 From: melissawm Date: Thu, 18 May 2023 15:32:49 -0300 Subject: [PATCH 1/7] DOC: Add patches and link to transformations in quickstart guide --- galleries/users_explain/quick_start.py | 30 +++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/galleries/users_explain/quick_start.py b/galleries/users_explain/quick_start.py index cf2d5850e6e5..ded42d588bde 100644 --- a/galleries/users_explain/quick_start.py +++ b/galleries/users_explain/quick_start.py @@ -206,8 +206,8 @@ # You may find older examples that use the ``pylab`` interface, # via ``from pylab import *``. This approach is strongly deprecated. # -# Making a helper functions -# ------------------------- +# Making helper functions +# ----------------------- # # If you need to make the same plots over and over again with different data # sets, or want to easily wrap Matplotlib methods, use the recommended @@ -558,8 +558,29 @@ def my_plotter(ax, data1, data2, param_dict): # control the size. Finally, the colorbar will have default locators # and formatters appropriate to the norm. These can be changed as for # other Axis objects. + +# %% +# Patches +# ======= # -# +# Patches are Artists with a face color and an edge color, which can be used to +# draw arbitrary two dimensional regions. In addition to the more general +# Polygon, there are wrappers and helpers for common shapes like Rectangles, +# Circles, Boxes, Ellipses, and more. + +fig, ax = plt.subplots() + +polygon = mpl.patches.Polygon(np.array([[1, 0], [0.5, 1.5], [2, 1]]), closed=True) +ax.add_patch(polygon) + +circle = mpl.patches.Circle((2, 2), 0.5, facecolor='orange', edgecolor='black') +ax.add_patch(circle) + +ax.set_xlim(0, 3) +ax.set_ylim(0, 3) +ax.set_box_aspect(1) + +# %% # Working with multiple Figures and Axes # ====================================== # @@ -588,3 +609,6 @@ def my_plotter(ax, data1, data2, param_dict): # For more plot types see :doc:`Plot types ` and the # :doc:`API reference `, in particular the # :doc:`Axes API `. +# +# For more information on coordinate systems and transformations, see the +# :ref:`transforms_tutorial`. From f2c2f77fd3433a0260237044a6ad54b73b5a5d97 Mon Sep 17 00:00:00 2001 From: melissawm Date: Mon, 22 May 2023 19:34:20 -0300 Subject: [PATCH 2/7] DOC: Add links to patch Artists and improve phrasing --- galleries/users_explain/quick_start.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/galleries/users_explain/quick_start.py b/galleries/users_explain/quick_start.py index ded42d588bde..51c67116923b 100644 --- a/galleries/users_explain/quick_start.py +++ b/galleries/users_explain/quick_start.py @@ -563,10 +563,12 @@ def my_plotter(ax, data1, data2, param_dict): # Patches # ======= # -# Patches are Artists with a face color and an edge color, which can be used to -# draw arbitrary two dimensional regions. In addition to the more general -# Polygon, there are wrappers and helpers for common shapes like Rectangles, -# Circles, Boxes, Ellipses, and more. +# :mod:`Patches ` are a family of Artists that can be used +# when drawing arbitrary two-dimensional regions. In addition to the general +# Patch Artists :class:`~.patches.PathPatch` and :class:`~.patches.Polygon`, +# common shapes have corresponding Patch Artists such as +# :class:`~.patches.Circle`, :class:`~.patches.Rectangle`, +# :class:`~.patches.Ellipse`, etc. fig, ax = plt.subplots() From be91fb7b1d72acf676b659833cf397e6bb1face0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Melissa=20Weber=20Mendon=C3=A7a?= Date: Tue, 23 May 2023 13:56:03 -0300 Subject: [PATCH 3/7] DOC: Improve styling on patches example code Co-authored-by: hannah --- galleries/users_explain/quick_start.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/galleries/users_explain/quick_start.py b/galleries/users_explain/quick_start.py index 51c67116923b..9d94524784c4 100644 --- a/galleries/users_explain/quick_start.py +++ b/galleries/users_explain/quick_start.py @@ -578,9 +578,7 @@ def my_plotter(ax, data1, data2, param_dict): circle = mpl.patches.Circle((2, 2), 0.5, facecolor='orange', edgecolor='black') ax.add_patch(circle) -ax.set_xlim(0, 3) -ax.set_ylim(0, 3) -ax.set_box_aspect(1) +ax.set(xlim=(0, 3), ylim=(0, 3), box_aspect=1) # %% # Working with multiple Figures and Axes From f1a58e5575a73c33d20c698d177c0fda9c52c2f4 Mon Sep 17 00:00:00 2001 From: melissawm Date: Thu, 25 May 2023 20:22:19 -0300 Subject: [PATCH 4/7] DOC: Add plot types section to quickstart Also creates a Patches under the Artists explanations. --- galleries/users_explain/artists/index.rst | 1 + galleries/users_explain/artists/patches.py | 28 +++++++++++++++ galleries/users_explain/quick_start.py | 41 +++++++++++----------- 3 files changed, 49 insertions(+), 21 deletions(-) create mode 100644 galleries/users_explain/artists/patches.py diff --git a/galleries/users_explain/artists/index.rst b/galleries/users_explain/artists/index.rst index d3f2918c9a91..66cab003da63 100644 --- a/galleries/users_explain/artists/index.rst +++ b/galleries/users_explain/artists/index.rst @@ -21,3 +21,4 @@ and :doc:`Axes <../axes/index>` are Artists, and generally contain Path effects guide Understanding the extent keyword argument of imshow transforms_tutorial + patches diff --git a/galleries/users_explain/artists/patches.py b/galleries/users_explain/artists/patches.py new file mode 100644 index 000000000000..50fcf1fb1b96 --- /dev/null +++ b/galleries/users_explain/artists/patches.py @@ -0,0 +1,28 @@ +""" +.. _patches_artists: + +======= +Patches +======= + +:mod:`Patches ` are a family of Artists that can be used +when drawing arbitrary two-dimensional regions. In addition to the general +Patch Artists :class:`~.patches.PathPatch` and :class:`~.patches.Polygon`, +common shapes have corresponding Patch Artists such as +:class:`~.patches.Circle`, :class:`~.patches.Rectangle`, +:class:`~.patches.Ellipse`, etc. +""" + +import matplotlib.pyplot as plt +import matplotlib as mpl +import numpy as np + +fig, ax = plt.subplots() + +polygon = mpl.patches.Polygon(np.array([[1, 0], [0.5, 1.5], [2, 1]]), closed=True) +ax.add_patch(polygon) + +circle = mpl.patches.Circle((2, 2), 0.5, facecolor='orange', edgecolor='black') +ax.add_patch(circle) + +ax.set(xlim=(0, 3), ylim=(0, 3), box_aspect=1) diff --git a/galleries/users_explain/quick_start.py b/galleries/users_explain/quick_start.py index 9d94524784c4..3374ed33fe04 100644 --- a/galleries/users_explain/quick_start.py +++ b/galleries/users_explain/quick_start.py @@ -111,6 +111,26 @@ # Artists are drawn to the **canvas**. Most Artists are tied to an Axes; such # an Artist cannot be shared by multiple Axes, or moved from one to another. # +# .. _plot_types_quickstart: +# +# Plot types +# ========== +# +# For an overview of the different types of plot you can create with Matplotlib, +# see the :ref:`Plot types gallery `. If you don't find the plot +# type you need, it may still be possible to create the visualization you want +# by combining existing Artists and plot elements. +# +# * To manipulate and customize points, see :class:`~.markers.MarkerStyle` +# * To manipulate and customize lines, see :class:`~.lines.Line2D` or +# :class:`~.collections.LineCollection` +# * To manipulate and customize regions, see :mod:`matplotlib.patches` +# * To manipulate and customize :mod:`images `, see +# :class:`~.image.AxesImage` +# * To manipulate and customize contours and (vector) fields, see +# `~.axes.Axes.contour` and `~.axes.Axes.quiver`, respectively. +# * For anything else, see :ref:`artists_tutorial`. +# # .. _input_types: # # Types of inputs to plotting functions @@ -559,27 +579,6 @@ def my_plotter(ax, data1, data2, param_dict): # and formatters appropriate to the norm. These can be changed as for # other Axis objects. -# %% -# Patches -# ======= -# -# :mod:`Patches ` are a family of Artists that can be used -# when drawing arbitrary two-dimensional regions. In addition to the general -# Patch Artists :class:`~.patches.PathPatch` and :class:`~.patches.Polygon`, -# common shapes have corresponding Patch Artists such as -# :class:`~.patches.Circle`, :class:`~.patches.Rectangle`, -# :class:`~.patches.Ellipse`, etc. - -fig, ax = plt.subplots() - -polygon = mpl.patches.Polygon(np.array([[1, 0], [0.5, 1.5], [2, 1]]), closed=True) -ax.add_patch(polygon) - -circle = mpl.patches.Circle((2, 2), 0.5, facecolor='orange', edgecolor='black') -ax.add_patch(circle) - -ax.set(xlim=(0, 3), ylim=(0, 3), box_aspect=1) - # %% # Working with multiple Figures and Axes # ====================================== From 26d4c993c528e74c1299ede4fca613cbc6eadb12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Melissa=20Weber=20Mendon=C3=A7a?= Date: Thu, 10 Aug 2023 20:07:45 -0300 Subject: [PATCH 5/7] Add example and reword plot types quickstart section --- galleries/users_explain/quick_start.py | 38 ++++++++++++++++++-------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/galleries/users_explain/quick_start.py b/galleries/users_explain/quick_start.py index 3374ed33fe04..9d309a0e00f4 100644 --- a/galleries/users_explain/quick_start.py +++ b/galleries/users_explain/quick_start.py @@ -119,17 +119,33 @@ # For an overview of the different types of plot you can create with Matplotlib, # see the :ref:`Plot types gallery `. If you don't find the plot # type you need, it may still be possible to create the visualization you want -# by combining existing Artists and plot elements. -# -# * To manipulate and customize points, see :class:`~.markers.MarkerStyle` -# * To manipulate and customize lines, see :class:`~.lines.Line2D` or -# :class:`~.collections.LineCollection` -# * To manipulate and customize regions, see :mod:`matplotlib.patches` -# * To manipulate and customize :mod:`images `, see -# :class:`~.image.AxesImage` -# * To manipulate and customize contours and (vector) fields, see -# `~.axes.Axes.contour` and `~.axes.Axes.quiver`, respectively. -# * For anything else, see :ref:`artists_tutorial`. +# by combining existing :ref:`Artists ` and customizing plot +# elements. For example, `~.matplotlib.axes.Axes.plot` returns a +# :class:`~.lines.Line2D` object and `~.matplotlib.axes.Axes.scatter` returns a +# :class:`~.collections.LineCollection`. +from matplotlib.lines import Line2D +from matplotlib.patches import Rectangle + +# Plot the data +x = np.array([3, 4, 9, 8, 9, 8, 0, 8, 4, 8]) +fig, ax = plt.subplots() +ax.plot(x, label='Data') + +# Computing the mean and standard deviation of the data +mean = np.mean(x) +std = np.std(x) + +# Adding a horizontal line for the mean, and a rectangle representing the +# standard deviation of the data +mean_line = Line2D([0, 10], [np.mean(x)]*2, color='red', label='Mean') +std_patch = Rectangle([0, mean-std], 10, 2*std, alpha=0.1, label='$\sigma$') + +# Add Artists to Axes object +ax.add_line(mean_line) +ax.add_patch(std_patch) +ax.legend() +# %% +# See also :ref:`artists_tutorial`. # # .. _input_types: # From 8ce593a6f358b3f677c52e1971bb07e45d9d51ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Melissa=20Weber=20Mendon=C3=A7a?= Date: Fri, 11 Aug 2023 10:13:07 -0300 Subject: [PATCH 6/7] Clear linting errors --- .flake8 | 1 + galleries/users_explain/quick_start.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.flake8 b/.flake8 index ee739cdf4231..c11645341933 100644 --- a/.flake8 +++ b/.flake8 @@ -60,6 +60,7 @@ per-file-ignores = galleries/users_explain/artists/transforms_tutorial.py: E402, E501 galleries/users_explain/colors/colormaps.py: E501 galleries/users_explain/colors/colors.py: E402 + galleries/users_explain/quick_start.py: E402 galleries/tutorials/artists.py: E402 galleries/users_explain/axes/constrainedlayout_guide.py: E402 galleries/users_explain/axes/legend_guide.py: E402 diff --git a/galleries/users_explain/quick_start.py b/galleries/users_explain/quick_start.py index 9d309a0e00f4..bd92cfbeea87 100644 --- a/galleries/users_explain/quick_start.py +++ b/galleries/users_explain/quick_start.py @@ -138,7 +138,7 @@ # Adding a horizontal line for the mean, and a rectangle representing the # standard deviation of the data mean_line = Line2D([0, 10], [np.mean(x)]*2, color='red', label='Mean') -std_patch = Rectangle([0, mean-std], 10, 2*std, alpha=0.1, label='$\sigma$') +std_patch = Rectangle([0, mean-std], 10, 2*std, alpha=0.1, label=r'$\sigma$') # Add Artists to Axes object ax.add_line(mean_line) From c588cfc47e1566ebc67686ed999c380f06519a7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Melissa=20Weber=20Mendon=C3=A7a?= Date: Mon, 4 Sep 2023 17:40:05 +0000 Subject: [PATCH 7/7] Improve example Co-authored-by: hannah --- galleries/users_explain/quick_start.py | 39 ++++++++++++++------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/galleries/users_explain/quick_start.py b/galleries/users_explain/quick_start.py index bd92cfbeea87..8f6f6c1e5f6c 100644 --- a/galleries/users_explain/quick_start.py +++ b/galleries/users_explain/quick_start.py @@ -116,36 +116,39 @@ # Plot types # ========== # -# For an overview of the different types of plot you can create with Matplotlib, +# For an overview of the different types of plots you can create with Matplotlib, # see the :ref:`Plot types gallery `. If you don't find the plot # type you need, it may still be possible to create the visualization you want -# by combining existing :ref:`Artists ` and customizing plot -# elements. For example, `~.matplotlib.axes.Axes.plot` returns a -# :class:`~.lines.Line2D` object and `~.matplotlib.axes.Axes.scatter` returns a -# :class:`~.collections.LineCollection`. -from matplotlib.lines import Line2D -from matplotlib.patches import Rectangle - -# Plot the data +# For example, Matplotlib does not provide a method to automatically annotate a +# distribution plot. Instead, you can create this visualization by combining the +# `~.matplotlib.axes.Axes.plot` method to draw the distribution, the +# `~.matplotlib.axes.Axes.axhline` method to draw the mean, and +# `~matplotlib.axes.Axes.axhspan` to shade the standard deviation region. + x = np.array([3, 4, 9, 8, 9, 8, 0, 8, 4, 8]) fig, ax = plt.subplots() -ax.plot(x, label='Data') -# Computing the mean and standard deviation of the data +# Compute the mean and standard deviation of the data mean = np.mean(x) std = np.std(x) -# Adding a horizontal line for the mean, and a rectangle representing the +# Add a horizontal line for the mean, and a rectangle representing the # standard deviation of the data -mean_line = Line2D([0, 10], [np.mean(x)]*2, color='red', label='Mean') -std_patch = Rectangle([0, mean-std], 10, 2*std, alpha=0.1, label=r'$\sigma$') +ln_data = ax.plot(x, label='Data') +ln_mean = ax.axhline(mean, color='red', label='Mean') +ln_std = ax.axhspan(mean-std, mean+std, alpha=0.1, label=r'$\sigma$') -# Add Artists to Axes object -ax.add_line(mean_line) -ax.add_patch(std_patch) ax.legend() + +# Now, you can use object methods to directly customize your plot. +# Note that ln_data is a list of `~.matplotlib.lines.Line2D` objects - we'll +# modify the first entry in this list. +ln_data[0].set_color('orange') +ln_mean.set_linestyle(':') +ln_std.set_hatch('oo') # %% -# See also :ref:`artists_tutorial`. +# For more information on creating artists from their constructors, see +# :ref:`artists_tutorial`. # # .. _input_types: # pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy