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

Skip to content

Commit 6d4c8db

Browse files
committed
DOC: fix clipped labels
1 parent 2e0c2bb commit 6d4c8db

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

tutorials/introductory/usage.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@
113113
# `numpy.recarray`, or a `pandas.DataFrame`. Matplotlib allows you provide
114114
# the ``data`` keyword argument and generate plots passing the strings
115115
# corresponding to the *x* and *y* variables.
116-
np.random.seed(19680801)
116+
np.random.seed(19680801) # seed the random number generator.
117117
data = {'a': np.arange(50),
118118
'c': np.random.randint(0, 50, 50),
119119
'd': np.random.randn(50)}
120120
data['b'] = data['a'] + 10 * np.random.randn(50)
121121
data['d'] = np.abs(data['d']) * 100
122122

123-
fig, ax = plt.subplots(figsize=(5, 2.7))
123+
fig, ax = plt.subplots(figsize=(5, 2.7), constrained_layout=True)
124124
ax.scatter('a', 'b', c='c', s='d', data=data)
125125
ax.set_xlabel('entry a')
126126
ax.set_ylabel('entry b')
@@ -146,7 +146,7 @@
146146
x = np.linspace(0, 2, 100) # Sample data.
147147

148148
# Note that even in the OO-style, we use `.pyplot.figure` to create the figure.
149-
fig, ax = plt.subplots(figsize=(5, 2.7)) # Create a figure and an axes.
149+
fig, ax = plt.subplots(figsize=(5, 2.7), constrained_layout=True)
150150
ax.plot(x, x, label='linear') # Plot some data on the axes.
151151
ax.plot(x, x**2, label='quadratic') # Plot more data on the axes...
152152
ax.plot(x, x**3, label='cubic') # ... and some more.
@@ -160,7 +160,7 @@
160160

161161
x = np.linspace(0, 2, 100) # Sample data.
162162

163-
plt.figure(figsize=(5, 2.7))
163+
plt.figure(figsize=(5, 2.7), constrained_layout=True)
164164
plt.plot(x, x, label='linear') # Plot some data on the (implicit) axes.
165165
plt.plot(x, x**2, label='quadratic') # etc.
166166
plt.plot(x, x**3, label='cubic')
@@ -287,7 +287,7 @@ def my_plotter(ax, data1, data2, param_dict):
287287

288288
mu, sigma = 100, 15
289289
x = mu + sigma * np.random.randn(10000)
290-
fig, ax = plt.subplots(figsize=(5, 2.7))
290+
fig, ax = plt.subplots(figsize=(5, 2.7), constrained_layout=True)
291291
# the histogram of the data
292292
n, bins, patches = ax.hist(x, 50, density=1, facecolor='C0', alpha=0.75)
293293

@@ -297,6 +297,7 @@ def my_plotter(ax, data1, data2, param_dict):
297297
ax.text(60, .025, r'$\mu=100,\ \sigma=15$')
298298
ax.axis([40, 160, 0, 0.03])
299299
ax.grid(True)
300+
plt.show()
300301

301302
###############################################################################
302303
# All of the `~.Axes.text` functions return a `matplotlib.text.Text`
@@ -414,7 +415,7 @@ def my_plotter(ax, data1, data2, param_dict):
414415
# Different scales can have different locators and formatters; for instance
415416
# the log-scale above uses `~.LogLocator` and `~.LogFormatter`. See
416417
# :doc:`/gallery/ticks/tick-locators` and
417-
# :doc:gallery/ticks/tick-formatters` for other formatters and
418+
# :doc:`/gallery/ticks/tick-formatters` for other formatters and
418419
# locators and information for writing your own.
419420
#
420421
# Plotting dates and strings

0 commit comments

Comments
 (0)