@@ -26,21 +26,19 @@ def _save_figure(objects='mhip', fmt="pdf", usetex=False):
26
26
mpl .use (fmt )
27
27
mpl .rcParams .update ({'svg.hashsalt' : 'asdf' , 'text.usetex' : usetex })
28
28
29
- fig = plt .figure ()
30
-
31
- if 'm' in objects :
29
+ def plot_markers (fig ):
32
30
# use different markers...
33
- ax1 = fig .add_subplot (1 , 6 , 1 )
31
+ ax = fig .add_subplot ()
34
32
x = range (10 )
35
- ax1 .plot (x , [1 ] * 10 , marker = 'D' )
36
- ax1 .plot (x , [2 ] * 10 , marker = 'x' )
37
- ax1 .plot (x , [3 ] * 10 , marker = '^' )
38
- ax1 .plot (x , [4 ] * 10 , marker = 'H' )
39
- ax1 .plot (x , [5 ] * 10 , marker = 'v' )
33
+ ax .plot (x , [1 ] * 10 , marker = 'D' )
34
+ ax .plot (x , [2 ] * 10 , marker = 'x' )
35
+ ax .plot (x , [3 ] * 10 , marker = '^' )
36
+ ax .plot (x , [4 ] * 10 , marker = 'H' )
37
+ ax .plot (x , [5 ] * 10 , marker = 'v' )
40
38
41
- if 'h' in objects :
39
+ def plot_hatch ( fig ) :
42
40
# also use different hatch patterns
43
- ax2 = fig .add_subplot (1 , 6 , 2 )
41
+ ax2 = fig .add_subplot ()
44
42
bars = (ax2 .bar (range (1 , 5 ), range (1 , 5 )) +
45
43
ax2 .bar (range (1 , 5 ), [6 ] * 4 , bottom = range (1 , 5 )))
46
44
ax2 .set_xticks ([1.5 , 2.5 , 3.5 , 4.5 ])
@@ -49,17 +47,17 @@ def _save_figure(objects='mhip', fmt="pdf", usetex=False):
49
47
for bar , pattern in zip (bars , patterns ):
50
48
bar .set_hatch (pattern )
51
49
52
- if 'i' in objects :
50
+ def plot_image (fig ):
51
+ axs = fig .subplots (1 , 3 , sharex = True , sharey = True )
53
52
# also use different images
54
53
A = [[1 , 2 , 3 ], [2 , 3 , 1 ], [3 , 1 , 2 ]]
55
- fig . add_subplot ( 1 , 6 , 3 ) .imshow (A , interpolation = 'nearest' )
54
+ axs [ 0 ] .imshow (A , interpolation = 'nearest' )
56
55
A = [[1 , 3 , 2 ], [1 , 2 , 3 ], [3 , 1 , 2 ]]
57
- fig . add_subplot ( 1 , 6 , 4 ) .imshow (A , interpolation = 'bilinear' )
56
+ axs [ 1 ] .imshow (A , interpolation = 'bilinear' )
58
57
A = [[2 , 3 , 1 ], [1 , 2 , 3 ], [2 , 1 , 3 ]]
59
- fig .add_subplot (1 , 6 , 5 ).imshow (A , interpolation = 'bicubic' )
60
-
61
- if 'p' in objects :
58
+ axs [2 ].imshow (A , interpolation = 'bicubic' )
62
59
60
+ def plot_paths (fig ):
63
61
# clipping support class, copied from demo_text_path.py gallery example
64
62
class PathClippedImagePatch (PathPatch ):
65
63
"""
@@ -85,21 +83,23 @@ def draw(self, renderer=None):
85
83
self .bbox_image .draw (renderer )
86
84
super ().draw (renderer )
87
85
86
+ subfigs = fig .subfigures (1 , 3 )
87
+
88
88
# add a polar projection
89
- px = fig .add_subplot (projection = "polar" )
89
+ px = subfigs [ 0 ] .add_subplot (projection = "polar" )
90
90
pimg = px .imshow ([[2 ]])
91
91
pimg .set_clip_path (Circle ((0 , 1 ), radius = 0.3333 ))
92
92
93
93
# add a text-based clipping path (origin: demo_text_path.py)
94
- ( ax1 , ax2 ) = fig . subplots ( 2 )
94
+ ax = subfigs [ 1 ]. add_subplot ( )
95
95
arr = plt .imread (get_sample_data ("grace_hopper.jpg" ))
96
96
text_path = TextPath ((0 , 0 ), "!?" , size = 150 )
97
97
p = PathClippedImagePatch (text_path , arr , ec = "k" )
98
98
offsetbox = AuxTransformBox (IdentityTransform ())
99
99
offsetbox .add_artist (p )
100
100
ao = AnchoredOffsetbox (loc = 'upper left' , child = offsetbox , frameon = True ,
101
101
borderpad = 0.2 )
102
- ax1 .add_artist (ao )
102
+ ax .add_artist (ao )
103
103
104
104
# add a 2x2 grid of path-clipped axes (origin: test_artist.py)
105
105
exterior = Path .unit_rectangle ().deepcopy ()
@@ -112,7 +112,8 @@ def draw(self, renderer=None):
112
112
star = Path .unit_regular_star (6 ).deepcopy ()
113
113
star .vertices *= 2.6
114
114
115
- (row1 , row2 ) = fig .subplots (2 , 2 , sharex = True , sharey = True )
115
+ (row1 , row2 ) = subfigs [2 ].subplots (2 , 2 , sharex = True , sharey = True ,
116
+ gridspec_kw = dict (hspace = 0 , wspace = 0 ))
116
117
for row in (row1 , row2 ):
117
118
ax1 , ax2 = row
118
119
collection = PathCollection ([star ], lw = 5 , edgecolor = 'blue' ,
@@ -128,8 +129,22 @@ def draw(self, renderer=None):
128
129
ax1 .set_xlim ([- 3 , 3 ])
129
130
ax1 .set_ylim ([- 3 , 3 ])
130
131
132
+ nfigs = len (objects ) + 1
133
+ fig = plt .figure (figsize = (7 , 3 * nfigs ))
134
+ subfigs = iter (fig .subfigures (nfigs , squeeze = False ).flat )
135
+ fig .subplots_adjust (bottom = 0.15 )
136
+
137
+ if 'm' in objects :
138
+ plot_markers (next (subfigs ))
139
+ if 'h' in objects :
140
+ plot_hatch (next (subfigs ))
141
+ if 'i' in objects :
142
+ plot_image (next (subfigs ))
143
+ if 'p' in objects :
144
+ plot_paths (next (subfigs ))
145
+
131
146
x = range (5 )
132
- ax = fig .add_subplot (1 , 6 , 6 )
147
+ ax = next ( subfigs ) .add_subplot ()
133
148
ax .plot (x , x )
134
149
ax .set_title ('A string $1+2+\\ sigma$' )
135
150
ax .set_xlabel ('A string $1+2+\\ sigma$' )
@@ -147,17 +162,15 @@ def draw(self, renderer=None):
147
162
("i" , "pdf" , False ),
148
163
("mhip" , "pdf" , False ),
149
164
("mhip" , "ps" , False ),
150
- pytest .param (
151
- "mhip" , "ps" , True , marks = [needs_usetex , needs_ghostscript ]),
165
+ pytest .param ("mhip" , "ps" , True , marks = [needs_usetex , needs_ghostscript ]),
152
166
("p" , "svg" , False ),
153
167
("mhip" , "svg" , False ),
154
168
pytest .param ("mhip" , "svg" , True , marks = needs_usetex ),
155
169
]
156
170
)
157
171
def test_determinism_check (objects , fmt , usetex ):
158
172
"""
159
- Output three times the same graphs and checks that the outputs are exactly
160
- the same.
173
+ Output the same graph three times and check that the outputs are exactly the same.
161
174
162
175
Parameters
163
176
----------
@@ -197,10 +210,11 @@ def test_determinism_check(objects, fmt, usetex):
197
210
)
198
211
def test_determinism_source_date_epoch (fmt , string ):
199
212
"""
200
- Test SOURCE_DATE_EPOCH support. Output a document with the environment
201
- variable SOURCE_DATE_EPOCH set to 2000-01-01 00:00 UTC and check that the
202
- document contains the timestamp that corresponds to this date (given as an
203
- argument).
213
+ Test SOURCE_DATE_EPOCH support.
214
+
215
+ Output a document with the environment variable SOURCE_DATE_EPOCH set to
216
+ 2000-01-01 00:00 UTC and check that the document contains the timestamp that
217
+ corresponds to this date (given as an argument).
204
218
205
219
Parameters
206
220
----------
0 commit comments