Skip to content

More (minor) plot types gallery fixes. #21136

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

Merged
merged 5 commits into from
Sep 23, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/sphinxext/gallery_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ def __call__(self, item):
# Basic
"plot", "scatter_plot", "bar", "stem", "step", "pie", "fill_between",
# Arrays
"imshow", "pcolormesh", "contourf", "quiver", "streamplot",
"imshow", "pcolormesh", "contour", "contourf", "quiver", "streamplot",
# Stats
"hist_plot", "boxplot_plot", "errorbar_plot", "violin",
"barbs", "eventplot", "hist2d", "hexbin",
# Unstructured
"tricontour", "tripcolor", "triplot",
"tricontour", "tricontourf", "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-gallery-nogrid.mplstyle
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This style is used for the plot_types gallery. It is considered private.

axes.grid: False
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'])
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# from the Matplotlib cheatsheet as used in our gallery:
# This style is used for the plot_types gallery. It is considered part of the private API.

axes.grid: True
axes.axisbelow: True
Expand Down
3 changes: 1 addition & 2 deletions plot_types/arrays/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery-nogrid')

# make data
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
Expand All @@ -17,7 +17,6 @@

# plot
fig, ax = plt.subplots()
ax.grid(False)

ax.contour(X, Y, Z, levels=levels)

Expand Down
2 changes: 1 addition & 1 deletion plot_types/arrays/contourf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery-nogrid')

# make data
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
Expand Down
5 changes: 2 additions & 3 deletions plot_types/arrays/imshow.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery-nogrid')

# 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 = (1 - X/2 + X**5 + Y**3) * np.exp(-X**2 - Y**2)
Z = Z[::16, ::16]

# plot
fig, ax = plt.subplots()
ax.grid(False)

ax.imshow(Z)

Expand Down
5 changes: 2 additions & 3 deletions plot_types/arrays/pcolormesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery-nogrid')

# 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 = (1 - X/2 + X**5 + Y**3) * np.exp(-X**2 - Y**2)

# sample unevenly in x:
dx = np.sqrt((np.arange(16) - 8)**2) + 6
Expand All @@ -26,7 +26,6 @@

# plot
fig, ax = plt.subplots()
ax.grid(False)

ax.pcolormesh(X, Y, Z, vmin=-0.5, vmax=1.0)

Expand Down
2 changes: 1 addition & 1 deletion plot_types/arrays/quiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery')

# make data
phi = np.linspace(0, 2 * np.pi, 8)
Expand Down
6 changes: 2 additions & 4 deletions plot_types/arrays/streamplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,18 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery-nogrid')

# 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 = (1 - X/2 + X**5 + Y**3) * np.exp(-X**2 - Y**2)
# 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()
ax.grid(False)

# plot stream plot
ax.streamplot(X[1:, 1:], Y[1:, 1:], U, V)

plt.show()
2 changes: 1 addition & 1 deletion plot_types/basic/bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""
import matplotlib.pyplot as plt
import numpy as np
plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery')

# make data:
np.random.seed(3)
Expand Down
2 changes: 1 addition & 1 deletion plot_types/basic/pie.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery-nogrid')


# make data
Expand Down
2 changes: 1 addition & 1 deletion plot_types/basic/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery')

# make data
x = np.linspace(0, 10, 100)
Expand Down
2 changes: 1 addition & 1 deletion plot_types/basic/scatter_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery')

# make the data
np.random.seed(3)
Expand Down
2 changes: 1 addition & 1 deletion plot_types/basic/stem.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery')

# make data
np.random.seed(3)
Expand Down
2 changes: 1 addition & 1 deletion plot_types/basic/step.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery')

# make data
np.random.seed(3)
Expand Down
2 changes: 1 addition & 1 deletion plot_types/stats/barbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery')

# make data:
np.random.seed(1)
Expand Down
2 changes: 1 addition & 1 deletion plot_types/stats/boxplot_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery')

# make data:
np.random.seed(10)
Expand Down
2 changes: 1 addition & 1 deletion plot_types/stats/errorbar_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery')

# make data:
np.random.seed(1)
Expand Down
2 changes: 1 addition & 1 deletion plot_types/stats/eventplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery')

# make data:
np.random.seed(1)
Expand Down
2 changes: 1 addition & 1 deletion plot_types/stats/hexbin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery-nogrid')

# make data: correlated + noise
np.random.seed(1)
Expand Down
2 changes: 1 addition & 1 deletion plot_types/stats/hist2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery-nogrid')

# make data: correlated + noise
np.random.seed(1)
Expand Down
2 changes: 1 addition & 1 deletion plot_types/stats/hist_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery')

# make data
np.random.seed(1)
Expand Down
2 changes: 1 addition & 1 deletion plot_types/stats/violin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery')

# make data:
np.random.seed(10)
Expand Down
19 changes: 6 additions & 13 deletions plot_types/unstructured/tricontour.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,17 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery-nogrid')

# make structured 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)
levels = np.linspace(Z.min(), Z.max(), 7)

# sample it to make unstructured x, y, z
# make data:
np.random.seed(1)
ysamp = np.random.randint(0, 256, size=250)
xsamp = np.random.randint(0, 256, size=250)
y = Y[:, 0][ysamp]
x = X[0, :][xsamp]
z = Z[ysamp, xsamp]
x = np.random.uniform(-3, 3, 256)
y = np.random.uniform(-3, 3, 256)
z = (1 - x/2 + x**5 + y**3) * np.exp(-x**2 - y**2)
levels = np.linspace(z.min(), z.max(), 7)

# plot:
fig, ax = plt.subplots()
ax.grid(False)

ax.plot(x, y, 'o', markersize=2, color='lightgrey')
ax.tricontour(x, y, z, levels=levels)
Expand Down
19 changes: 6 additions & 13 deletions plot_types/unstructured/tricontourf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,17 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery-nogrid')

# make structured 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)
levels = np.linspace(np.min(Z), np.max(Z), 7)

# sample it to make unstructured x, y, z
# make data:
np.random.seed(1)
ysamp = np.random.randint(0, 256, size=250)
xsamp = np.random.randint(0, 256, size=250)
y = Y[:, 0][ysamp]
x = X[0, :][xsamp]
z = Z[ysamp, xsamp]
x = np.random.uniform(-3, 3, 256)
y = np.random.uniform(-3, 3, 256)
z = (1 - x/2 + x**5 + y**3) * np.exp(-x**2 - y**2)
levels = np.linspace(z.min(), z.max(), 7)

# plot:
fig, ax = plt.subplots()
ax.grid(False)

ax.plot(x, y, 'o', markersize=2, color='grey')
ax.tricontourf(x, y, z, levels=levels)
Expand Down
16 changes: 5 additions & 11 deletions plot_types/unstructured/tripcolor.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery-nogrid')

# make structured 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)

# sample it to make unstructured x, y, z
# make data:
np.random.seed(1)
ysamp = np.random.randint(0, 256, size=250)
xsamp = np.random.randint(0, 256, size=250)
y = Y[:, 0][ysamp]
x = X[0, :][xsamp]
z = Z[ysamp, xsamp]
x = np.random.uniform(-3, 3, 256)
y = np.random.uniform(-3, 3, 256)
z = (1 - x/2 + x**5 + y**3) * np.exp(-x**2 - y**2)

# plot:
fig, ax = plt.subplots()
Expand Down
15 changes: 5 additions & 10 deletions plot_types/unstructured/triplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,16 @@
import matplotlib.pyplot as plt
import numpy as np

plt.style.use('mpl_plot_gallery')
plt.style.use('_mpl-gallery-nogrid')

# make structured data
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))

# sample it to make x, y, z
# make data:
np.random.seed(1)
ysamp = np.random.randint(0, 256, size=250)
xsamp = np.random.randint(0, 256, size=250)
y = Y[:, 0][ysamp]
x = X[0, :][xsamp]
x = np.random.uniform(-3, 3, 256)
y = np.random.uniform(-3, 3, 256)
z = (1 - x/2 + x**5 + y**3) * np.exp(-x**2 - y**2)

# plot:
fig, ax = plt.subplots()
ax.grid(False)

ax.triplot(x, y)

Expand Down