Skip to content
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

DOC: new plot gallery #19703

Merged
merged 11 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/_templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<li><a href="{{ pathto('users/installing') }}">Installation</a></li>
<li><a href="{{ pathto('contents') }}">Documentation</a></li>
<li><a href="{{ pathto('api/index') }}">API</a></li>
<li><a href="{{ pathto('plot_types/index') }}">Plot Types</a></li>
<li><a href="{{ pathto('gallery/index') }}">Examples</a></li>
<li><a href="{{ pathto('tutorials/index') }}">Tutorials</a></li>
<li><a href="{{ pathto('devel/index') }}">Contributing</a></li>
Expand Down
4 changes: 2 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ def _check_dependencies():

# Sphinx gallery configuration
sphinx_gallery_conf = {
'examples_dirs': ['../examples', '../tutorials'],
'examples_dirs': ['../examples', '../tutorials', '../plot_types'],
'filename_pattern': '^((?!sgskip).)*$',
'gallery_dirs': ['gallery', 'tutorials'],
'gallery_dirs': ['gallery', 'tutorials', 'plot_types'],
'doc_module': ('matplotlib', 'mpl_toolkits'),
'reference_url': {
'matplotlib': None,
Expand Down
18 changes: 17 additions & 1 deletion doc/sphinxext/gallery_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@
'../examples/showcase',
'../tutorials/introductory',
'../tutorials/intermediate',
'../tutorials/advanced']
'../tutorials/advanced',
'../plot_types/basic',
'../plot_types/arrays',
'../plot_types/stats',
'../plot_types/unstructured',
]


class MplExplicitOrder(ExplicitOrder):
Expand Down Expand Up @@ -60,6 +65,17 @@ def __call__(self, item):
"color_demo",
# pies
"pie_features", "pie_demo2",

# **Plot Types
# Basic
"plot", "scatter_plot", "bar", "stem", "step", "pie", "fill_between",
# Arrays
"imshow", "pcolormesh", "contourf", "quiver", "streamplot",
# Stats
"hist_plot", "boxplot_plot", "errorbar_plot", "violin",
"barbs", "eventplot", "hist2d", "hexbin",
# Unstructured
"tricontour", "tripcolor", "triplot",
]
explicit_subsection_order = [item + ".py" for item in list_all]

Expand Down
19 changes: 19 additions & 0 deletions lib/matplotlib/mpl-data/stylelib/mpl_plot_gallery.mplstyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# from the Matplotlib cheatsheet as used in our gallery:

axes.grid: True
axes.axisbelow: True

figure.figsize: 2, 2
# make it so the axes labels don't show up. Obviously
# not good style for any quantitative analysis:
figure.subplot.left: 0.01
figure.subplot.right: 0.99
figure.subplot.bottom: 0.01
figure.subplot.top: 0.99

xtick.major.size: 0.0
ytick.major.size: 0.0

# colors:
image.cmap : Blues
# axes.prop_cycle: cycler('color', ['FF7F0E', '1F77B4', '2CA02C'])
11 changes: 11 additions & 0 deletions plot_types/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.. _plot_types:

Plot types
==========

This gallery lists many of the plotting commands in Matplotlib,
(but not all of them!).

Note that we have stripped all labels, but they are present by default.
See the `gallery <../gallery/index.html>`_ for many more examples and
the `tutorials page <../tutorials/index.html>`_ for longer examples.
6 changes: 6 additions & 0 deletions plot_types/arrays/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _array_plots:

Plots of arrays and fields
--------------------------

Plotting for arrays of data ``Z(x, y)`` and fields ``U(x, y), V(x, y)``
23 changes: 23 additions & 0 deletions plot_types/arrays/contourf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
=====================================
contour[f]([X, Y], Z, [levels=], ...)
=====================================
"""
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')

# make data
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
Z = (1 - X/2. + X**5 + Y**3)*np.exp(-X**2-Y**2)
Z = Z - Z.min()
levs = np.linspace(np.min(Z), np.max(Z), 7)

# plot
fig, ax = plt.subplots()

plt.contourf(X, Y, Z, levels=levs)
plt.contour(X, Y, Z, levels=levs, colors="white", linewidths=0.5)

plt.show()
26 changes: 26 additions & 0 deletions plot_types/arrays/imshow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
=======================
imshow(Z, [cmap=], ...)
=======================
"""

import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')

# make data
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
Z = (1 - X/2. + X**5 + Y**3) * np.exp(-X**2 - Y**2)
Z = Z - Z.min()
Z = Z[::16, ::16]

# plot
fig, ax = plt.subplots()

ax.imshow(Z, extent=[0, 8, 0, 8], interpolation="nearest",
cmap=plt.get_cmap('Blues'), vmin=0, vmax=1.6)

ax.set_xticks([])
ax.set_yticks([])
plt.show()
33 changes: 33 additions & 0 deletions plot_types/arrays/pcolormesh.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
===================================
pcolormesh([X, Y], Z, [cmap=], ...)
===================================

`~.axes.Axes.pcolormesh` is more flexible than `~.axes.Axes.imshow` in that
the x and y vectors need not be equally spaced (indeed they can be skewed).

"""
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')

# make full-res data
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
Z = (1 - X/2. + X**5 + Y**3) * np.exp(-X**2 - Y**2)
Z = Z - Z.min()

# sample unevenly in x:
dx = np.sqrt((np.arange(16) - 8)**2) + 6
dx = np.floor(dx / sum(dx) * 255)
xint = np.cumsum(dx).astype('int')
X = X[0, xint]
Y = Y[::8, 0]
Z = Z[::8, :][:, xint]

# plot
fig, ax = plt.subplots()

ax.pcolormesh(X, Y, Z, vmin=0, vmax=1.5, shading='nearest')

plt.show()
27 changes: 27 additions & 0 deletions plot_types/arrays/quiver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
=========================
quiver([X, Y], U, V, ...)
=========================
"""
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')

# make data
T = np.linspace(0, 2*np.pi, 8)
X, Y = 4 + 1 * np.cos(T), 4 + 1 * np.sin(T)
U, V = 1.5 * np.cos(T), 1.5 * np.sin(T)

# plot
fig, ax = plt.subplots()

plt.quiver(X, Y, U, V, color="C0", angles='xy',
scale_units='xy', scale=0.5, width=.05)

ax.set_xlim(0, 8)
ax.set_xticks(np.arange(1, 8))
ax.set_ylim(0, 8)
ax.set_yticks(np.arange(1, 8))

plt.show()
26 changes: 26 additions & 0 deletions plot_types/arrays/streamplot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
========================
streamplot([X, Y], U, V)
========================
"""
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')

# make a stream function:
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
Z = (1 - X/2. + X**5 + Y**3) * np.exp(-X**2 - Y**2)
Z = Z - Z.min()
# make U and V out of the streamfunction:
V = np.diff(Z[1:, :], axis=1)
U = -np.diff(Z[:, 1:], axis=0)

# plot:
fig, ax = plt.subplots()
# contour stream function
ax.contour(X, Y, Z, colors='C1', alpha=0.5, zorder=1, linewidths=3)
# plot stream plot
ax.streamplot(X[1:, 1:], Y[1:, 1:], U, V, zorder=2)

plt.show()
6 changes: 6 additions & 0 deletions plot_types/basic/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. _basic_plots:

Basic
-----

Basic plot types, usually x versus y.
24 changes: 24 additions & 0 deletions plot_types/basic/bar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
======================
bar[h](x, height, ...)
======================
"""
import matplotlib.pyplot as plt
import numpy as np
plt.style.use('mpl_plot_gallery')

# make data:
np.random.seed(3)
X = 0.5 + np.arange(8)
Y = np.random.uniform(2, 7, len(X))

# plot
fig, ax = plt.subplots()

ax.bar(X, Y, width=1, edgecolor="white", linewidth=0.7)

ax.set_xlim(0, 8)
ax.set_xticks(np.arange(1, 8))
ax.set_ylim(0, 8)
ax.set_yticks(np.arange(1, 8))
plt.show()
31 changes: 31 additions & 0 deletions plot_types/basic/pie.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
====================
pie(X, explode, ...)
====================
"""
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')


# make data
X = [1, 2, 3, 4]
colors = np.zeros((len(X), 4))
colors[:] = mpl.colors.to_rgba("C0")
colors[:, 3] = np.linspace(0.25, 0.75, len(X))

# plot
fig, ax = plt.subplots()
ax.pie(X, colors=["white"]*len(X), radius=3, center=(4, 4),
wedgeprops={"linewidth": 1, "edgecolor": "white"}, frame=True)
ax.pie(X, colors=colors, radius=3, center=(4, 4),
wedgeprops={"linewidth": 1, "edgecolor": "white"}, frame=True)

ax.set_xlim(0, 8)
ax.set_xticks(np.arange(1, 8))
ax.set_ylim(0, 8)
ax.set_yticks(np.arange(1, 8))

plt.show()
25 changes: 25 additions & 0 deletions plot_types/basic/plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
======================
plot([X], Y, [fmt]...)
======================
"""

import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')

# make data
X = np.linspace(0, 10, 100)
Y = 4 + 2 * np.sin(2 * X)

# plot
fig, ax = plt.subplots()

ax.plot(X, Y, linewidth=2.0)

ax.set_xlim(0, 8)
ax.set_xticks(np.arange(1, 8))
ax.set_ylim(0, 8)
ax.set_yticks(np.arange(1, 8))
plt.show()
27 changes: 27 additions & 0 deletions plot_types/basic/scatter_plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
==================
scatter(X, Y, ...)
==================
"""
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')

# make the data
np.random.seed(3)
X = 4 + np.random.normal(0, 2, 24)
Y = 4 + np.random.normal(0, 2, len(X))
# size and color:
S = np.random.uniform(15, 80, len(X))

# plot
fig, ax = plt.subplots()

ax.scatter(X, Y, s=S, c=-S, cmap=plt.get_cmap('Blues'), vmin=-100, vmax=0)

ax.set_xlim(0, 8)
ax.set_xticks(np.arange(1, 8))
ax.set_ylim(0, 8)
ax.set_yticks(np.arange(1, 8))
plt.show()
25 changes: 25 additions & 0 deletions plot_types/basic/stem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
=================
stem([x], y, ...)
=================
"""
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')

# make data
np.random.seed(3)
X = 0.5 + np.arange(8)
Y = np.random.uniform(2, 7, len(X))

# plot
fig, ax = plt.subplots()

ax.stem(X, Y, bottom=0, linefmt="-", markerfmt="d")

ax.set_xlim(0, 8)
ax.set_xticks(np.arange(1, 8))
ax.set_ylim(0, 8)
ax.set_yticks(np.arange(1, 8))
plt.show()