2525# `.Axes.plot` to draw some data on the axes:
2626
2727fig , 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:
124123fig , ax = plt .subplots (figsize = (5 , 2.7 ), constrained_layout = True )
125124ax .scatter ('a' , 'b' , c = 'c' , s = 'd' , data = data )
126125ax .set_xlabel ('entry a' )
127- ax .set_ylabel ('entry b' )
128- plt .show ()
126+ ax .set_ylabel ('entry b' );
129127
130128##############################################################################
131129# .. _coding_styles:
155153ax .set_xlabel ('x label' ) # Add an x-label to the axes.
156154ax .set_ylabel ('y label' ) # Add a y-label to the axes.
157155ax .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:
170167plt .xlabel ('x label' )
171168plt .ylabel ('y label' )
172169plt .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
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#
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
201197def my_plotter (ax , data1 , data2 , param_dict ):
@@ -212,8 +208,7 @@ def my_plotter(ax, data1, data2, param_dict):
212208xdata = np .arange (len (data1 )) # make an ordinal for this
213209fig , (ax1 , ax2 ) = plt .subplots (1 , 2 , figsize = (5 , 2.7 ))
214210my_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 package, or any other
@@ -235,8 +230,7 @@ def my_plotter(ax, data1, data2, param_dict):
235230x = np .arange (len (data1 ))
236231ax .plot (x , np .cumsum (data1 ), color = 'blue' , linewidth = 3 , linestyle = '--' )
237232l , = 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
251245fig , ax = plt .subplots (figsize = (5 , 2.7 ))
252246x = 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):
275268ax .plot (data2 , 'd' , label = 'data2' )
276269ax .plot (data3 , 'v' , label = 'data3' )
277270ax .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
294286mu , sigma = 115 , 15
@@ -302,8 +294,7 @@ def my_plotter(ax, data1, data2, param_dict):
302294ax .set_title ('Aardvark lengths\n (not really)' )
303295ax .text (75 , .025 , r'$\mu=115,\ \sigma=15$' )
304296ax .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):
347338ax .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):
366356ax .plot (np .arange (len (data1 )), data1 , label = 'data1' )
367357ax .plot (np .arange (len (data2 )), data2 , label = 'data2' )
368358ax .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):
396385axs [0 ].plot (xdata , data )
397386
398387axs [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):
418406axs [1 ].plot (xdata , data1 )
419407axs [1 ].set_xticks (np .arange (0 , 100 , 30 ), ['zero' , '30' , 'sixty' , '90' ])
420408axs [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):
439426dates = np .arange (np .datetime64 ('2021-11-15' ), np .datetime64 ('2021-12-25' ),
440427 np .timedelta64 (1 , 'h' ))
441428data = 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):
452438fig , ax = plt .subplots (figsize = (5 , 2.7 ), constrained_layout = True )
453439categories = ['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
487472pc = axs [1 , 1 ].scatter (data1 , data2 , c = data3 , cmap = 'RdBu_r' )
488473fig .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