8000 [DOC]: adding a grid to the style sheet reference. by kostyafarber · Pull Request #24020 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

[DOC]: adding a grid to the style sheet reference. #24020

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 6 commits into from
Oct 1, 2022
Merged
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
22 changes: 16 additions & 6 deletions examples/style_sheets/style_sheets_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
from matplotlib.patches import Rectangle

# Fixing random state for reproducibility
np.random.seed(19680801)
Expand Down Expand Up @@ -65,8 +66,11 @@ def plot_colored_circles(ax, prng, nb_samples=15):
for sty_dict, j in zip(plt.rcParams['axes.prop_cycle'], range(nb_samples)):
ax.add_patch(plt.Circle(prng.normal(scale=3, size=2),
radius=1.0, color=sty_dict['color']))
# Force the limits to be the same across the styles (because different
# styles may have different numbers of available colors).
ax.grid(visible=True)

# Add title for enabling grid
plt.title('ax.grid(True)', family='monospace', fontsize='small')

ax.set_xlim([-4, 8])
ax.set_ylim([-5, 6])
ax.set_aspect('equal', adjustable='box') # to plot circles as circles
Expand All @@ -91,6 +95,7 @@ def plot_histograms(ax, prng, nb_samples=10000):
values = prng.beta(a, b, size=nb_samples)
ax.hist(values, histtype="stepfilled", bins=30,
alpha=0.8, density=True)

# Add a small annotation.
ax.annotate('Annotation', xy=(0.25, 4.25),
xytext=(0.9, 0.9), textcoords=ax.transAxes,
Expand All @@ -110,7 +115,7 @@ def plot_figure(style_label=""):
prng = np.random.RandomState(96917002)

fig, axs = plt.subplots(ncols=6, nrows=1, num=style_label,
figsize=(14.8, 2.7), constrained_layout=True)
figsize=(14.8, 2.8), constrained_layout=True)

# make a suptitle, in the same style for all subfigures,
# except those with dark backgrounds, which get a lighter color:
Expand All @@ -126,10 +131,15 @@ def plot_figure(style_label=""):
plot_scatter(axs[0], prng)
plot_image_and_patch(axs[1], prng)
plot_bar_graphs(axs[2], prng)
plot_colored_circles(axs[3], prng)
plot_colored_lines(axs[4])
plot_histograms(axs[5], prng)
plot_colored_lines(axs[3])
plot_histograms(axs[4], prng)
plot_colored_circles(axs[5], prng)

# add divider
rec = Rectangle((1 + 0.025, -2), 0.05, 16,
clip_on=False, color='gray')

axs[4].add_artist(rec)

if __name__ == "__main__":

Expand Down
0