22
33import numpy as np
44import matplotlib .pyplot as plt
5- from matplotlib .ticker import MultipleLocator , FuncFormatter
5+ from matplotlib .ticker import AutoMinorLocator , MultipleLocator , FuncFormatter
66
7- np .random .seed (123 )
7+
8+ np .random .seed (19680801 )
89
910X = np .linspace (0.5 , 3.5 , 100 )
1011Y1 = 3 + np .cos (X )
1112Y2 = 1 + np .cos (1 + X / 0.75 )/ 2
1213Y3 = np .random .uniform (Y1 , Y2 , len (X ))
1314
14- fig = plt .figure (figsize = (8 , 8 ), facecolor = "w" )
15+ fig = plt .figure (figsize = (8 , 8 ))
1516ax = fig .add_subplot (1 , 1 , 1 , aspect = 1 )
1617
1718
@@ -21,9 +22,9 @@ def minor_tick(x, pos):
2122 return "%.2f" % x
2223
2324ax .xaxis .set_major_locator (MultipleLocator (1.000 ))
24- ax .xaxis .set_minor_locator (MultipleLocator ( 0.250 ))
25+ ax .xaxis .set_minor_locator (AutoMinorLocator ( 4 ))
2526ax .yaxis .set_major_locator (MultipleLocator (1.000 ))
26- ax .yaxis .set_minor_locator (MultipleLocator ( 0.250 ))
27+ ax .yaxis .set_minor_locator (AutoMinorLocator ( 4 ))
2728ax .xaxis .set_minor_formatter (FuncFormatter (minor_tick ))
2829
2930ax .set_xlim (0 , 4 )
@@ -38,13 +39,14 @@ def minor_tick(x, pos):
3839
3940ax .plot (X , Y1 , c = (0.25 , 0.25 , 1.00 ), lw = 2 , label = "Blue signal" , zorder = 10 )
4041ax .plot (X , Y2 , c = (1.00 , 0.25 , 0.25 ), lw = 2 , label = "Red signal" )
41- ax .scatter (X , Y3 , c = 'w' )
42+ ax .plot (X , Y3 , linewidth = 0 ,
43+ marker = 'o' , markerfacecolor = 'w' , markeredgecolor = 'k' )
4244
43- ax .set_title ("Anatomy of a figure" , fontsize = 20 )
45+ ax .set_title ("Anatomy of a figure" , fontsize = 20 , verticalalignment = 'bottom' )
4446ax .set_xlabel ("X axis label" )
4547ax .set_ylabel ("Y axis label" )
4648
47- ax .legend (frameon = False )
49+ ax .legend ()
4850
4951
5052def circle (x , y , radius = 0.15 ):
@@ -62,32 +64,32 @@ def text(x, y, text):
6264
6365
6466# Minor tick
65- circle (0.50 , - .05 )
66- text (0.50 , - 0.25 , "Minor tick label" )
67+ circle (0.50 , - 0.10 )
68+ text (0.50 , - 0.32 , "Minor tick label" )
6769
6870# Major tick
69- circle (4.00 , 2 .00 )
70- text (4.00 , 1 .80 , "Major tick" )
71+ circle (- 0.03 , 4 .00 )
72+ text (0.03 , 3 .80 , "Major tick" )
7173
7274# Minor tick
73- circle (0.25 , 4.00 )
74- text (0.25 , 3.80 , "Minor tick" )
75+ circle (0.00 , 3.50 )
76+ text (0.00 , 3.30 , "Minor tick" )
7577
7678# Major tick label
77- circle (- 0.05 , 3.00 )
78- text (- 0.05 , 2.80 , "Major tick label" )
79+ circle (- 0.15 , 3.00 )
80+ text (- 0.15 , 2.80 , "Major tick label" )
7981
8082# X Label
81- circle (1.80 , - 0.22 )
82- text (1.80 , - 0.4 , "X axis label" )
83+ circle (1.80 , - 0.27 )
84+ text (1.80 , - 0.45 , "X axis label" )
8385
8486# Y Label
85- circle (- 0.20 , 1.80 )
86- text (- 0.20 , 1.6 , "Y axis label" )
87+ circle (- 0.27 , 1.80 )
88+ text (- 0.27 , 1.6 , "Y axis label" )
8789
8890# Title
89- circle (1.60 , 4.10 )
90- text (1.60 , 3.9 , "Title" )
91+ circle (1.60 , 4.13 )
92+ text (1.60 , 3.93 , "Title" )
9193
9294# Blue plot
9395circle (1.75 , 2.80 )
@@ -106,8 +108,8 @@ def text(x, y, text):
106108text (3.00 , 2.80 , "Grid" )
107109
108110# Legend
109- circle (3.70 , 3.75 )
110- text (3.70 , 3.55 , "Legend" )
111+ circle (3.70 , 3.80 )
112+ text (3.70 , 3.60 , "Legend" )
111113
112114# Axes
113115circle (0.5 , 0.5 )
0 commit comments