Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DOC: Add patches and link to transformations in quickstart guide #25911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions galleries/users_explain/artists/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ and :doc:`Axes <../axes/index>` are Artists, and generally contain
Path effects guide <patheffects_guide>
Understanding the extent keyword argument of imshow <imshow_extent>
transforms_tutorial
patches
28 changes: 28 additions & 0 deletions galleries/users_explain/artists/patches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""
.. _patches_artists:

=======
Patches
=======

:mod:`Patches <matplotlib.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)
50 changes: 46 additions & 4 deletions galleries/users_explain/quick_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,45 @@
# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Plot types
# Custom plot types

I think that's what this section is really about, or making custom plot types

# ==========
#
# For an overview of the different types of plots you can create with Matplotlib,
# see the :ref:`Plot types gallery <plot_types>`. If you don't find the plot
# type you need, it may still be possible to create the visualization you want
# 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()

# Compute the mean and standard deviation of the data
mean = np.mean(x)
std = np.std(x)

# Add a horizontal line for the mean, and a rectangle representing the
# standard deviation of the data
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$')

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')
# %%
# For more information on creating artists from their constructors, see
# :ref:`artists_tutorial`.
#
# .. _input_types:
#
# Types of inputs to plotting functions
Expand Down Expand Up @@ -206,8 +245,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
Expand Down Expand Up @@ -558,8 +597,8 @@ 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.
#
#

# %%
# Working with multiple Figures and Axes
# ======================================
#
Expand Down Expand Up @@ -588,3 +627,6 @@ def my_plotter(ax, data1, data2, param_dict):
# For more plot types see :doc:`Plot types </plot_types/index>` and the
# :doc:`API reference </api/index>`, in particular the
# :doc:`Axes API </api/axes_api>`.
#
# For more information on coordinate systems and transformations, see the
# :ref:`transforms_tutorial`.