11
11
12
12
###############################################################################
13
13
# As usual we would start by defining the imports and create a figure with
14
- # subplots. To have some space for the big cake, we use
15
- # :meth:`subplots_adjust <matplotlib.figure.Figure.subplots_adjust>` to
16
- # adjust the spacings.
17
-
18
- import numpy as np
19
- import matplotlib .pyplot as plt
20
-
21
- fig , (ax , ax2 ) = plt .subplots (nrows = 2 , figsize = (6 , 6 ))
22
- fig .subplots_adjust (top = 0.92 , bottom = 0.08 )
23
- plt .setp ((ax , ax2 ), aspect = "equal" )
24
-
25
-
14
+ # subplots.
26
15
# Now it's time for the pie. Starting with a pie recipe, we create the data
27
16
# and a list of labels from it.
28
17
#
41
30
# the left central point of the legend will be at the left central point of the
42
31
# bounding box, spanning from ``(1,0)`` to ``(1.5,1)`` in axes coordinates.
43
32
33
+ import numpy as np
34
+ import matplotlib .pyplot as plt
35
+
36
+ fig , ax = plt .subplots (figsize = (6 , 3 ), subplot_kw = dict (aspect = "equal" ))
44
37
45
38
recipe = ["375 g flour" ,
46
39
"75 g sugar" ,
@@ -68,7 +61,10 @@ def func(pct, allvals):
68
61
69
62
ax .set_title ("Matplotlib bakery: A pie" )
70
63
64
+ plt .show ()
65
+
71
66
67
+ ###############################################################################
72
68
# Now it's time for the donut. Starting with a donut recipe, we transcribe
73
69
# the data to numbers (converting 1 egg to 50 g), and directly plot the pie.
74
70
# The pie? Wait... it's going to be donut, is it not?
@@ -91,6 +87,9 @@ def func(pct, allvals):
91
87
# * finally, create the annotation with all the previously
92
88
# determined parameters.
93
89
90
+
91
+ fig , ax = plt .subplots (figsize = (6 , 3 ), subplot_kw = dict (aspect = "equal" ))
92
+
94
93
recipe = ["225 g flour" ,
95
94
"90 g sugar" ,
96
95
"1 egg" ,
@@ -100,7 +99,7 @@ def func(pct, allvals):
100
99
101
100
data = [225 , 90 , 50 , 60 , 100 , 5 ]
102
101
103
- wedges , texts = ax2 .pie (data , wedgeprops = dict (width = 0.5 ), startangle = - 40 )
102
+ wedges , texts = ax .pie (data , wedgeprops = dict (width = 0.5 ), startangle = - 40 )
104
103
105
104
bbox_props = dict (boxstyle = "square,pad=0.3" , fc = "w" , ec = "k" , lw = 0.72 )
106
105
kw = dict (xycoords = 'data' , textcoords = 'data' , arrowprops = dict (arrowstyle = "-" ),
@@ -113,9 +112,14 @@ def func(pct, allvals):
113
112
horizontalalignment = ["" , "left" , "right" ][int (np .sign (x ))]
114
113
connectionstyle = "angle,angleA=0,angleB={}" .format (ang )
115
114
kw ["arrowprops" ].update ({"connectionstyle" : connectionstyle })
116
- ax2 .annotate (recipe [i ], xy = (x , y ), xytext = (1.35 * np .sign (x ), 1.4 * y ),
115
+ ax .annotate (recipe [i ], xy = (x , y ), xytext = (1.35 * np .sign (x ), 1.4 * y ),
117
116
horizontalalignment = horizontalalignment , ** kw )
118
117
119
- ax2 .set_title ("Matplotlib bakery: A donut" )
118
+ ax .set_title ("Matplotlib bakery: A donut" )
120
119
121
120
plt .show ()
121
+
122
+ ###############################################################################
123
+ # And here it is, the donut. Note however, that if we were to use this recipe,
124
+ # the ingredients would suffice for around 6 donuts - producing one huge
125
+ # donut is untested and might result in kitchen errors.
0 commit comments