28
28
# `.Axes.plot` to draw some data on the Axes:
29
29
30
30
fig ,ax = plt .subplots ()# Create a figure containing a single axes.
31
- ax .plot ([1 ,2 ,3 ,4 ], [1 ,4 ,2 ,3 ]); # Plot some data on the axes.
31
+ ax .plot ([1 ,2 ,3 ,4 ], [1 ,4 ,2 ,3 ])# Plot some data on the axes.
32
32
33
33
###############################################################################
34
34
# .. _figure_parts:
126
126
fig ,ax = plt .subplots (figsize = (5 ,2.7 ),layout = 'constrained' )
127
127
ax .scatter ('a' ,'b' ,c = 'c' ,s = 'd' ,data = data )
128
128
ax .set_xlabel ('entry a' )
129
- ax .set_ylabel ('entry b' );
129
+ ax .set_ylabel ('entry b' )
130
130
131
131
##############################################################################
132
132
# .. _coding_styles:
159
159
ax .set_xlabel ('x label' )# Add an x-label to the axes.
160
160
ax .set_ylabel ('y label' )# Add a y-label to the axes.
161
161
ax .set_title ("Simple Plot" )# Add a title to the axes.
162
- ax .legend (); # Add a legend.
162
+ ax .legend ()# Add a legend.
163
163
164
164
###############################################################################
165
165
# or the pyplot-style:
173
173
plt .xlabel ('x label' )
174
174
plt .ylabel ('y label' )
175
175
plt .title ("Simple Plot" )
176
- plt .legend ();
176
+ plt .legend ()
177
177
178
178
###############################################################################
179
179
# (In addition, there is a third approach, for the case when embedding
@@ -213,7 +213,7 @@ def my_plotter(ax, data1, data2, param_dict):
213
213
data1 ,data2 ,data3 ,data4 = np .random .randn (4 ,100 )# make 4 random data sets
214
214
fig , (ax1 ,ax2 )= plt .subplots (1 ,2 ,figsize = (5 ,2.7 ))
215
215
my_plotter (ax1 ,data1 ,data2 , {'marker' :'x' })
216
- my_plotter (ax2 ,data3 ,data4 , {'marker' :'o' });
216
+ my_plotter (ax2 ,data3 ,data4 , {'marker' :'o' })
217
217
218
218
###############################################################################
219
219
# Note that if you want to install these as a python package, or any other
@@ -235,7 +235,7 @@ def my_plotter(ax, data1, data2, param_dict):
235
235
x = np .arange (len (data1 ))
236
236
ax .plot (x ,np .cumsum (data1 ),color = 'blue' ,linewidth = 3 ,linestyle = '--' )
237
237
l ,= ax .plot (x ,np .cumsum (data2 ),color = 'orange' ,linewidth = 2 )
238
- l .set_linestyle (':' );
238
+ l .set_linestyle (':' )
239
239
240
240
###############################################################################
241
241
# Colors
@@ -248,7 +248,7 @@ def my_plotter(ax, data1, data2, param_dict):
248
248
# from the interior:
249
249
250
250
fig ,ax = plt .subplots (figsize = (5 ,2.7 ))
251
- ax .scatter (data1 ,data2 ,s = 50 ,facecolor = 'C0' ,edgecolor = 'k' );
251
+ ax .scatter (data1 ,data2 ,s = 50 ,facecolor = 'C0' ,edgecolor = 'k' )
252
252
253
253
###############################################################################
254
254
# Linewidths, linestyles, and markersizes
@@ -272,7 +272,7 @@ def my_plotter(ax, data1, data2, param_dict):
272
272
ax .plot (data2 ,'d' ,label = 'data2' )
273
273
ax .plot (data3 ,'v' ,label = 'data3' )
274
274
ax .plot (data4 ,'s' ,label = 'data4' )
275
- ax .legend ();
275
+ ax .legend ()
276
276
277
277
###############################################################################
278
278
#
@@ -298,7 +298,7 @@ def my_plotter(ax, data1, data2, param_dict):
298
298
ax .set_title ('Aardvark lengths\n (not really)' )
299
299
ax .text (75 ,.025 ,r'$\mu=115,\ \sigma=15$' )
300
300
ax .axis ([55 ,175 ,0 ,0.03 ])
301
- ax .grid (True );
301
+ ax .grid (True )
302
302
303
303
###############################################################################
304
304
# All of the `~.Axes.text` functions return a `matplotlib.text.Text`
@@ -342,7 +342,7 @@ def my_plotter(ax, data1, data2, param_dict):
342
342
ax .annotate ('local max' ,xy = (2 ,1 ),xytext = (3 ,1.5 ),
343
343
arrowprops = dict (facecolor = 'black' ,shrink = 0.05 ))
344
344
345
- ax .set_ylim (- 2 ,2 );
345
+ ax .set_ylim (- 2 ,2 )
346
346
347
347
###############################################################################
348
348
# In this basic example, both *xy* and *xytext* are in data coordinates.
@@ -360,7 +360,7 @@ def my_plotter(ax, data1, data2, param_dict):
360
360
ax .plot (np .arange (len (data1 )),data1 ,label = 'data1' )
361
361
ax .plot (np .arange (len (data2 )),data2 ,label = 'data2' )
362
362
ax .plot (np .arange (len (data3 )),data3 ,'d' ,label = 'data3' )
363
- ax .legend ();
363
+ ax .legend ()
364
364
365
365
##############################################################################
366
366
# Legends in Matplotlib are quite flexible in layout, placement, and what
@@ -391,7 +391,7 @@ def my_plotter(ax, data1, data2, param_dict):
391
391
axs [0 ].plot (xdata ,data )
392
392
393
393
axs [1 ].set_yscale ('log' )
394
- axs [1 ].plot (xdata ,data );
394
+ axs [1 ].plot (xdata ,data )
395
395
396
396
##############################################################################
397
397
# The scale sets the mapping from data values to spacing along the Axis. This
@@ -413,7 +413,7 @@ def my_plotter(ax, data1, data2, param_dict):
413
413
axs [1 ].plot (xdata ,data1 )
414
414
axs [1 ].set_xticks (np .arange (0 ,100 ,30 ), ['zero' ,'30' ,'sixty' ,'90' ])
415
415
axs [1 ].set_yticks ([- 1.5 ,0 ,1.5 ])# note that we don't need to specify labels
416
- axs [1 ].set_title ('Manual ticks' );
416
+ axs [1 ].set_title ('Manual ticks' )
417
417
418
418
##############################################################################
419
419
# Different scales can have different locators and formatters; for instance
@@ -435,7 +435,7 @@ def my_plotter(ax, data1, data2, param_dict):
435
435
data = np .cumsum (np .random .randn (len (dates )))
436
436
ax .plot (dates ,data )
437
437
cdf = mpl .dates .ConciseDateFormatter (ax .xaxis .get_major_locator ())
438
- ax .xaxis .set_major_formatter (cdf );
438
+ ax .xaxis .set_major_formatter (cdf )
439
439
440
440
##############################################################################
441
441
# For more information see the date examples
@@ -447,7 +447,7 @@ def my_plotter(ax, data1, data2, param_dict):
447
447
fig ,ax = plt .subplots (figsize = (5 ,2.7 ),layout = 'constrained' )
448
448
categories = ['turnips' ,'rutabaga' ,'cucumber' ,'pumpkins' ]
449
449
450
- ax .bar (categories ,np .random .rand (len (categories )));
450
+ ax .bar (categories ,np .random .rand (len (categories )))
451
451
452
452
##############################################################################
453
453
# One caveat about categorical plotting is that some methods of parsing
@@ -561,7 +561,7 @@ def my_plotter(ax, data1, data2, param_dict):
561
561
['lowleft' ,'right' ]],layout = 'constrained' )
562
562
axd ['upleft' ].set_title ('upleft' )
563
563
axd ['lowleft' ].set_title ('lowleft' )
564
- axd ['right' ].set_title ('right' );
564
+ axd ['right' ].set_title ('right' )
565
565
566
566
###############################################################################
567
567
# Matplotlib has quite sophisticated tools for arranging Axes: See