Skip to content

Commit 479ff82

Browse files
authored
Merge pull request matplotlib#28135 from meeseeksmachine/auto-backport-of-pr-28134-on-v3.9.x
Backport PR matplotlib#28134 on branch v3.9.x (DOC: Minor improvements on quickstart)
2 parents 9b88c14 + 03b2383 commit 479ff82

File tree

2 files changed

+26
-23
lines changed

2 files changed

+26
-23
lines changed

.flake8

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ per-file-ignores =
4747
lib/mpl_toolkits/axisartist/angle_helper.py: E221
4848

4949
doc/conf.py: E402
50+
galleries/users_explain/quick_start.py: E402
5051
galleries/users_explain/artists/paths.py: E402
5152
galleries/users_explain/artists/patheffects_guide.py: E402
5253
galleries/users_explain/artists/transforms_tutorial.py: E402, E501

galleries/users_explain/quick_start.py

+25-23
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import numpy as np
1818

1919
# sphinx_gallery_thumbnail_number = 3
20-
import matplotlib as mpl
2120

2221
# %%
2322
#
@@ -29,16 +28,18 @@
2928
# area where points can be specified in terms of x-y coordinates (or theta-r
3029
# in a polar plot, x-y-z in a 3D plot, etc.). The simplest way of
3130
# creating a Figure with an Axes is using `.pyplot.subplots`. We can then use
32-
# `.Axes.plot` to draw some data on the Axes:
31+
# `.Axes.plot` to draw some data on the Axes, and `~.pyplot.show` to display
32+
# the figure:
3333

34-
fig, ax = plt.subplots() # Create a figure containing a single Axes.
34+
fig, ax = plt.subplots() # Create a figure containing a single Axes.
3535
ax.plot([1, 2, 3, 4], [1, 4, 2, 3]) # Plot some data on the Axes.
36+
plt.show() # Show the figure.
3637

3738
# %%
3839
#
39-
# Note that to get this Figure to display, you may have to call ``plt.show()``,
40-
# depending on your backend. For more details of Figures and backends, see
41-
# :ref:`figure-intro`.
40+
# Depending on the environment you are working in, ``plt.show()`` can be left
41+
# out. This is for example the case with Jupyter notebooks, which
42+
# automatically show all figures created in a code cell.
4243
#
4344
# .. _figure_parts:
4445
#
@@ -54,24 +55,24 @@
5455
#
5556
# The **whole** figure. The Figure keeps
5657
# track of all the child :class:`~matplotlib.axes.Axes`, a group of
57-
# 'special' Artists (titles, figure legends, colorbars, etc), and
58+
# 'special' Artists (titles, figure legends, colorbars, etc.), and
5859
# even nested subfigures.
5960
#
60-
# The easiest way to create a new Figure is with pyplot::
61+
# Typically, you'll create a new Figure through one of the following
62+
# functions::
6163
#
62-
# fig = plt.figure() # an empty figure with no Axes
63-
# fig, ax = plt.subplots() # a figure with a single Axes
64+
# fig = plt.figure() # an empty figure with no Axes
65+
# fig, ax = plt.subplots() # a figure with a single Axes
6466
# fig, axs = plt.subplots(2, 2) # a figure with a 2x2 grid of Axes
6567
# # a figure with one Axes on the left, and two on the right:
6668
# fig, axs = plt.subplot_mosaic([['left', 'right_top'],
6769
# ['left', 'right_bottom']])
6870
#
69-
# It is often convenient to create the Axes together with the Figure, but you
70-
# can also manually add Axes later on. Note that many
71-
# :ref:`Matplotlib backends <backends>` support zooming and
72-
# panning on figure windows.
71+
# `~.pyplot.subplots()` and `~.pyplot.subplot_mosaic` are convenience functions
72+
# that additionally create Axes objects inside the Figure, but you can also
73+
# manually add Axes later on.
7374
#
74-
# For more on Figures, see :ref:`figure-intro`.
75+
# For more on Figures, including panning and zooming, see :ref:`figure-intro`.
7576
#
7677
# :class:`~matplotlib.axes.Axes`
7778
# ------------------------------
@@ -86,10 +87,9 @@
8687
# :meth:`~matplotlib.axes.Axes.set_xlabel`), and a y-label set via
8788
# :meth:`~matplotlib.axes.Axes.set_ylabel`).
8889
#
89-
# The :class:`~.axes.Axes` class and its member functions are the primary
90-
# entry point to working with the OOP interface, and have most of the
91-
# plotting methods defined on them (e.g. ``ax.plot()``, shown above, uses
92-
# the `~.Axes.plot` method)
90+
# The `~.axes.Axes` methods are the primary interface for configuring
91+
# most parts of your plot (adding data, controlling axis scales and
92+
# limits, adding labels etc.).
9393
#
9494
# :class:`~matplotlib.axis.Axis`
9595
# ------------------------------
@@ -446,13 +446,14 @@ def my_plotter(ax, data1, data2, param_dict):
446446
# well as floating point numbers. These get special locators and formatters
447447
# as appropriate. For dates:
448448

449+
from matplotlib.dates import ConciseDateFormatter
450+
449451
fig, ax = plt.subplots(figsize=(5, 2.7), layout='constrained')
450452
dates = np.arange(np.datetime64('2021-11-15'), np.datetime64('2021-12-25'),
451453
np.timedelta64(1, 'h'))
452454
data = np.cumsum(np.random.randn(len(dates)))
453455
ax.plot(dates, data)
454-
cdf = mpl.dates.ConciseDateFormatter(ax.xaxis.get_major_locator())
455-
ax.xaxis.set_major_formatter(cdf)
456+
ax.xaxis.set_major_formatter(ConciseDateFormatter(ax.xaxis.get_major_locator()))
456457

457458
# %%
458459
# For more information see the date examples
@@ -506,6 +507,8 @@ def my_plotter(ax, data1, data2, param_dict):
506507
# Often we want to have a third dimension in a plot represented by colors in
507508
# a colormap. Matplotlib has a number of plot types that do this:
508509

510+
from matplotlib.colors import LogNorm
511+
509512
X, Y = np.meshgrid(np.linspace(-3, 3, 128), np.linspace(-3, 3, 128))
510513
Z = (1 - X/2 + X**5 + Y**3) * np.exp(-X**2 - Y**2)
511514

@@ -518,8 +521,7 @@ def my_plotter(ax, data1, data2, param_dict):
518521
fig.colorbar(co, ax=axs[0, 1])
519522
axs[0, 1].set_title('contourf()')
520523

521-
pc = axs[1, 0].imshow(Z**2 * 100, cmap='plasma',
522-
norm=mpl.colors.LogNorm(vmin=0.01, vmax=100))
524+
pc = axs[1, 0].imshow(Z**2 * 100, cmap='plasma', norm=LogNorm(vmin=0.01, vmax=100))
523525
fig.colorbar(pc, ax=axs[1, 0], extend='both')
524526
axs[1, 0].set_title('imshow() with LogNorm()')
525527

0 commit comments

Comments
 (0)