8000 DOC: suppress extra prints · matplotlib/matplotlib@26fc6a1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 26fc6a1

Browse files
committed
DOC: suppress extra prints
1 parent 94d2fd5 commit 26fc6a1

File tree

2 files changed

+28
-44
lines changed

2 files changed

+28
-44
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ per-file-ignores =
100100
tutorials/introductory/images.py: E402, E501
101101
tutorials/introductory/pyplot.py: E402, E501
102102
tutorials/introductory/sample_plots.py: E501
103-
tutorials/introductory/usage.py: E501
103+
tutorials/introductory/usage.py: E703
104104
tutorials/text/annotations.py: E402, E501
105105
tutorials/text/text_intro.py: E402
106106
tutorials/text/text_props.py: E501

tutorials/introductory/usage.py

Lines changed: 27 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
# `.Axes.plot` to draw some data on the axes:
2626

2727
fig, ax = plt.subplots() # Create a figure containing a single axes.
28-
ax.plot([1, 2, 3, 4], [1, 4, 2, 3]) # Plot some data on the axes.
29-
plt.show()
28+
ax.plot([1, 2, 3, 4], [1, 4, 2, 3]); # Plot some data on the axes.
3029

3130
###############################################################################
3231
# .. _figure_parts:
@@ -124,8 +123,7 @@
124123
fig, ax = plt.subplots(figsize=(5, 2.7), constrained_layout=True)
125124
ax.scatter('a', 'b', c='c', s='d', data=data)
126125
ax.set_xlabel('entry a')
127-
ax.set_ylabel('entry b')
128-
plt.show()
126+
ax.set_ylabel('entry b');
129127

130128
##############################################################################
131129
# .. _coding_styles:
@@ -155,8 +153,7 @@
155153
ax.set_xlabel('x label') # Add an x-label to the axes.
156154
ax.set_ylabel('y label') # Add a y-label to the axes.
157155
ax.set_title("Simple Plot") # Add a title to the axes.
158-
ax.legend() # Add a legend.
159-
plt.show()
156+
ax.legend(); # Add a legend.
160157

161158
###############################################################################
162159
# or the pyplot-style:
@@ -170,8 +167,7 @@
170167
plt.xlabel('x label')
171168
plt.ylabel('y label')
172169
plt.title("Simple Plot")
173-
plt.legend()
174-
plt.show()
170+
plt.legend();
175171

176172
###############################################################################
177173
# (In addition, there is a third approach, for the case when embedding
@@ -182,8 +178,8 @@
182178
# Matplotlib's documentation and examples use both the OO and the pyplot
183179
# styles. In general, we suggest using the OO style, particularly for
184180
# complicated plots, and functions and scripts that are intended to be reused
185-
# as part of a larger project. However, the pyplot style can be very conveneient
186-
# for quick interactive work.
181+
# as part of a larger project. However, the pyplot style can be very
182+
# conveneient for quick interactive work.
187183
#
188184
# .. note::
189185
#
@@ -193,9 +189,9 @@
193189
# Making a helper functions
194190
# -------------------------
195191
#
196-
# If you need to make the same plots over and over again with different data sets,
197-
# or want to easily wrap Matplotlib methods, use the recommended signature function
198-
# below.
192+
# If you need to make the same plots over and over again with different data
193+
# sets, or want to easily wrap Matplotlib methods, use the recommended
194+
# signature function below.
199195

200196

201197
def my_plotter(ax, data1, data2, param_dict):
@@ -212,8 +208,7 @@ def my_plotter(ax, data1, data2, param_dict):
212208
xdata = np.arange(len(data1)) # make an ordinal for this
213209
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(5, 2.7))
214210
my_plotter(ax1, data1, data2, {'marker': 'x'})
215-
my_plotter(ax2, data3, data4, {'marker': 'o'})
216-
plt.show()
211+
my_plotter(ax2, data3, data4, {'marker': 'o'});
217212

218213
###############################################################################
219214
# Note that if you want to install these as a python pac 628C kage, or any other
@@ -235,8 +230,7 @@ def my_plotter(ax, data1, data2, param_dict):
235230
x = np.arange(len(data1))
236231
ax.plot(x, np.cumsum(data1), color='blue', linewidth=3, linestyle='--')
237232
l, = ax.plot(x, np.cumsum(data2), color='orange', linewidth=2)
238-
l.set_linestyle(':')
239-
plt.show()
233+
l.set_linestyle(':');
240234

241235
###############################################################################
242236
# Colors
@@ -250,8 +244,7 @@ def my_plotter(ax, data1, data2, param_dict):
250244

251245
fig, ax = plt.subplots(figsize=(5, 2.7))
252246
x = np.arange(len(data1))
253-
ax.scatter(data1, data2, s=50, facecolor='C0', edgecolor='k')
254-
plt.show()
247+
ax.scatter(data1, data2, s=50, facecolor='C0', edgecolor='k');
255248

256249
###############################################################################
257250
# Linewidths, linestyles, and markersizes
@@ -275,10 +268,9 @@ def my_plotter(ax, data1, data2, param_dict):
275268
ax.plot(data2, 'd', label='data2')
276269
ax.plot(data3, 'v', label='data3')
277270
ax.plot(data4, 's', label='data4')
278-
ax.legend()
279-
plt.show()
271+
ax.legend();
280272

281-
################################################################################
273+
###############################################################################
282274
#
283275
# Labelling plots
284276
# ===============
@@ -287,8 +279,8 @@ def my_plotter(ax, data1, data2, param_dict):
287279
# --------------------
288280
#
289281
# `~.Axes.set_xlabel`, `~.Axes.set_ylabel`, and `~.Axes.set_title` are used to
290-
# add text in the indicated locations (see :doc:`/tutorials/text/text_intro` for
291-
# more discussion). Text can also be directly added to plots using
282+
# add text in the indicated locations (see :doc:`/tutorials/text/text_intro`
283+
# for more discussion). Text can also be directly added to plots using
292284
# `~.Axes.text`:
293285

294286
mu, sigma = 115, 15
@@ -302,8 +294,7 @@ def my_plotter(ax, data1, data2, param_dict):
302294
ax.set_title('Aardvark lengths\n (not really)')
303295
ax.text(75, .025, r'$\mu=115,\ \sigma=15$')
304296
ax.axis([55, 175, 0, 0.03])
305-
ax.grid(True)
306-
plt.show()
297+
ax.grid(True);
307298

308299
###############################################################################
309300
# All of the `~.Axes.text` functions return a `matplotlib.text.Text`
@@ -347,8 +338,7 @@ def my_plotter(ax, data1, data2, param_dict):
347338
ax.annotate('local max', xy=(2, 1), xytext=(3, 1.5),
348339
arrowprops=dict(facecolor='black', shrink=0.05))
349340

350-
ax.set_ylim(-2, 2)
351-
plt.show()
341+
ax.set_ylim(-2, 2);
352342

353343
###############################################################################
354344
# In this basic example, both *xy* and *xytext* are in data coordinates.
@@ -366,8 +356,7 @@ def my_plotter(ax, data1, data2, param_dict):
366356
ax.plot(np.arange(len(data1)), data1, label='data1')
367357
ax.plot(np.arange(len(data2)), data2, label='data2')
368358
ax.plot(np.arange(len(data3)), data3, 'd', label='data3')
369-
ax.legend()
370-
plt.show()
359+
ax.legend();
371360

372361
##############################################################################
373362
# Legends in Matplotlib are quite flexible in layout, placement, and what
@@ -377,9 +366,9 @@ def my_plotter(ax, data1, data2, param_dict):
377366
# Axis scales and ticks
378367
# =====================
379368
#
380-
# Each Axes has two (or three) `~.axis.Axis` objects represnting the x- and y-axis.
381-
# These control the *scale* of the axis, the tick *Locators* and the tick
382-
# *Formatters*.
369+
# Each Axes has two (or three) `~.axis.Axis` objects represnting the x- and
370+
# y-axis. These control the *scale* of the axis, the tick *Locators* and the
371+
# tick *Formatters*.
383372
#
384373
# Scales
385374
# ------
@@ -396,8 +385,7 @@ def my_plotter(ax, data1, data2, param_dict):
396385
axs[0].plot(xdata, data)
397386

398387
axs[1].set_yscale('log')
399-
axs[1].plot(xdata, data)
400-
plt.show()
388+
axs[1].plot(xdata, data);
401389

402390
##############################################################################
403391
# The scale sets the mapping from data values to spacing along the Axis. This
@@ -418,8 +406,7 @@ def my_plotter(ax, data1, data2, param_dict):
418406
axs[1].plot(xdata, data1)
419407
axs[1].set_xticks(np.arange(0, 100, 30), ['zero', '30', 'sixty', '90'])
420408
axs[1].set_yticks([-1.5, 0, 1.5]) # note that we don't need to specify labels
421-
axs[1].set_title('Manual ticks')
422-
plt.show()
409+
axs[1].set_title('Manual ticks');
423410

424411
##############################################################################
425412
# Different scales can have different locators and formatters; for instance
@@ -439,8 +426,7 @@ def my_plotter(ax, data1, data2, param_dict):
439426
dates = np.arange(np.datetime64('2021-11-15'), np.datetime64('2021-12-25'),
440427
np.timedelta64(1, 'h'))
441428
data = np.cumsum(np.random.randn(len(dates)))
442-
ax.plot(dates, data)
443-
plt.show()
429+
ax.plot(dates, data);
444430

445431
##############################################################################
446432
# For more information see the date examples
@@ -452,8 +438,7 @@ def my_plotter(ax, data1, data2, param_dict):
452438
fig, ax = plt.subplots(figsize=(5, 2.7), constrained_layout=True)
453439
categories = ['turnips', 'rutabega', 'cucumber', 'pumpkins']
454440

455-
ax.bar(categories, np.random.rand(len(categories)))
456-
plt.show()
441+
ax.bar(categories, np.random.rand(len(categories)));
457442

458443
##############################################################################
459444
# One caveat about categorical plotting is that some methods of parsing
@@ -486,8 +471,7 @@ def my_plotter(ax, data1, data2, param_dict):
486471

487472
pc = axs[1, 1].scatter(data1, data2, c=data3, cmap='RdBu_r')
488473
fig.colorbar(pc, ax=axs[1, 1], extend='both')
489-
axs[1, 1].set_title('scatter()')
490-
plt.show()
474+
axs[1, 1].set_title('scatter()');
491475

492476
##############################################################################
493477
# Colormaps

0 commit comments

Comments
 (0)
0