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

Skip to content

Commit ad10fbb

Browse files
committed
Fix typos, use more clever annotation position and use tight_layout
1 parent 39b4402 commit ad10fbb

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

examples/style_sheets/style_sheets_reference.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
The different plots are heavily similar to the other ones in the style sheet
55
gallery.
66
"""
7+
78
import numpy as np
89
import matplotlib.pyplot as plt
910

@@ -13,14 +14,14 @@ def plot_scatter(ax, prng, nb_samples=100):
1314
"""
1415
for mu, sigma, marker in [(-.5, 0.75, 'o'), (0.75, 1., 's')]:
1516
x, y = prng.normal(loc=mu, scale=sigma, size=(2, nb_samples))
16-
ax.plot(x, y, marker=marker, ls='')
17+
ax.plot(x, y, ls='none', marker=marker)
1718
ax.set_xlabel('X-label')
1819
ax.set_ylabel('Y-label')
1920
return ax
2021

2122

2223
def plot_colored_sinusoidal_lines(ax):
23-
""" Plot sinusoidal lines with colors from default color cycle.
24+
""" Plots sinusoidal lines with colors following the style color cycle.
2425
"""
2526
L = 2*np.pi
2627
x = np.linspace(0, L)
@@ -33,7 +34,7 @@ def plot_colored_sinusoidal_lines(ax):
3334

3435

3536
def plot_bar_graphs(ax, prng, min_value=5, max_value=25, nb_samples=5):
36-
""" Plot two bar graphs side by side, with letters as xticklabels.
37+
""" Plots two bar graphs side by side, with letters as xticklabels.
3738
"""
3839
x = np.arange(nb_samples)
3940
ya, yb = prng.randint(min_value, max_value, size=(2, nb_samples))
@@ -46,11 +47,11 @@ def plot_bar_graphs(ax, prng, min_value=5, max_value=25, nb_samples=5):
4647

4748

4849
def plot_colored_circles(ax, prng, nb_samples=15):
49-
""" Plot circle patches.
50+
""" Plots circle patches.
5051
51-
NB: drawing a fixed amount of samples, rather than using the length of
52-
the color cycle, because different styles may have different numbers of
53-
colors.
52+
NB: draws a fixed amount of samples, rather than using the length of
53+
the color cycle, because different styles may have different numbers
54+
of colors.
5455
"""
5556
for sty_dict, j in zip(plt.rcParams['axes.prop_cycle'], range(nb_samples)):
5657
ax.add_patch(plt.Circle(prng.normal(scale=3, size=2),
@@ -64,7 +65,7 @@ def plot_colored_circles(ax, prng, nb_samples=15):
6465

6566

6667
def plot_image_and_patch(ax, prng, size=(20, 20)):
67-
""" Plot an image with random values and superimpose a circular patch.
68+
""" Plots an image with random values and superimposes a circular patch.
6869
"""
6970
values = prng.random_sample(size=size)
7071
ax.imshow(values, interpolation='none')
@@ -73,15 +74,16 @@ def plot_image_and_patch(ax, prng, size=(20, 20)):
7374

7475

7576
def plot_histograms(ax, prng, nb_samples=10000):
76-
""" Plot 4 histograms and a text annotation.
77+
""" Plots 4 histograms and a text annotation.
7778
"""
7879
params = ((10, 10), (4, 12), (50, 12), (6, 55))
7980
for a, b in params:
8081
values = prng.beta(a, b, size=nb_samples)
8182
ax.hist(values, histtype="stepfilled", bins=30, alpha=0.8, normed=True)
8283
# Add a small annotation.
8384
ax.annotate('Annotation', xy=(0.25, 4.25), xycoords='data',
84-
xytext=(0.4, 10), textcoords='data',
85+
xytext=(0.9, 0.9), textcoords='axes fraction',
86+
va="top", ha="right",
8587
bbox=dict(boxstyle="round", alpha=0.2),
8688
arrowprops=dict(
8789
arrowstyle="->",
@@ -92,7 +94,7 @@ def plot_histograms(ax, prng, nb_samples=10000):
9294

9395
def plot_figure(style_label=None):
9496
"""
95-
Setup and plot the demonstration figure with the style `style_label`.
97+
Sets up and plots the demonstration figure with the style `style_label`.
9698
If `style_label` is None, fall back to the `default` style.
9799
"""
98100
if style_label is None:
@@ -112,6 +114,8 @@ def plot_figure(style_label=None):
112114
plot_colored_sinusoidal_lines(axes[1, 1])
113115
plot_histograms(axes[1, 2], prng)
114116

117+
fig.tight_layout()
118+
115119
return fig
116120

117121

0 commit comments

Comments
 (0)