9
9
from mpl_toolkits .axes_grid1 import host_subplot
10
10
from mpl_toolkits .axes_grid1 import make_axes_locatable
11
11
from mpl_toolkits .axes_grid1 import AxesGrid
12
- from mpl_toolkits .axes_grid1 .inset_locator import zoomed_inset_axes , mark_inset
12
+ from mpl_toolkits .axes_grid1 .inset_locator import zoomed_inset_axes , \
13
+ mark_inset , BboxConnectorPatch
13
14
from mpl_toolkits .axes_grid1 .anchored_artists import AnchoredSizeBar
14
15
15
16
from matplotlib .colors import LogNorm
17
+ from matplotlib .transforms import Bbox , TransformedBbox , \
18
+ blended_transform_factory
16
19
from itertools import product
17
20
18
21
import numpy as np
@@ -155,6 +158,91 @@ def get_demo_image():
155
158
ax .add_artist (asb )
156
159
157
160
161
+ @image_comparison (
162
+ baseline_images = ['fill_facecolor' ], extensions = ['png' ],
163
+ remove_text = True , style = 'mpl20' )
164
+ def test_fill_facecolor ():
165
+ fig , ax = plt .subplots (1 , 5 )
166
+ fig .set_size_inches (5 , 5 )
167
+ trans1 = blended_transform_factory (ax [0 ].transData , ax [0 ].transData )
168
+ trans2 = blended_transform_factory (ax [1 ].transData , ax [1 ].transData )
169
+ trans3 = blended_transform_factory (ax [2 ].transData , ax [2 ].transData )
170
+ trans4 = blended_transform_factory (ax [3 ].transData , ax [3 ].transData )
171
+ trans5 = blended_transform_factory (ax [4 ].transData , ax [4 ].transData )
172
+ for i in range (1 , 4 ):
173
+ ax [i ].yaxis .set_visible (False )
174
+ ax [4 ].yaxis .tick_right ()
175
+ bbox = Bbox .from_extents (0 , 0.4 , 1 , 0.6 )
176
+
177
+ # fill with blue by setting 'fc' field
178
+ bbox1 = TransformedBbox (bbox , trans1 )
179
+ bbox2 = TransformedBbox (bbox , trans2 )
180
+ # set color to BboxConnectorPatch
181
+ p = BboxConnectorPatch (
182
+ bbox1 , bbox2 , loc1a = 1 , loc2a = 2 , loc1b = 4 , loc2b = 3 ,
183
+ ec = "r" , fc = "b" )
184
+ p .set_clip_on (False )
185
+ ax [0 ].add_patch (p )
186
+ # set color to marked area
187
+ axins = zoomed_inset_axes (ax [0 ], 1 , loc = 1 )
188
+ axins .set_xlim (0 , 0.2 )
189
+ axins .set_ylim (0 , 0.2 )
190
+ plt .gca ().axes .get_xaxis ().set_ticks ([])
191
+ plt .gca ().axes .get_yaxis ().set_ticks ([])
192
+ mark_inset (ax [0 ], axins , loc1 = 2 , loc2 = 4 , fc = "b" , ec = "0.5" )
193
+
194
+ # fill with yellow by setting 'facecolor' field
195
+ bbox3 = TransformedBbox (bbox , trans2 )
196
+ bbox4 = TransformedBbox (bbox , trans3 )
197
+ # set color to BboxConnectorPatch
198
+ p = BboxConnectorPatch (
199
+ bbox3 , bbox4 , loc1a = 1 , loc2a = 2 , loc1b = 4 , loc2b = 3 ,
200
+ ec = "r" , facecolor = "y" )
201
+ p .set_clip_on (False )
202
+ ax [1 ].add_patch (p )
203
+ # set color to marked area
204
+ axins = zoomed_inset_axes (ax [1 ], 1 , loc = 1 )
205
+ axins .set_xlim (0 , 0.2 )
206
+ axins .set_ylim (0 , 0.2 )
207
+ plt .gca ().axes .get_xaxis ().set_ticks ([])
208
+ plt .gca ().axes .get_yaxis ().set_ticks ([])
209
+ mark_inset (ax [1 ], axins , loc1 = 2 , loc2 = 4 , facecolor = "y" , ec = "0.5" )
210
+
211
+ # fill with green by setting 'color' field
212
+ bbox5 = TransformedBbox (bbox , trans3 )
213
+ bbox6 = TransformedBbox (bbox , trans4 )
214
+ # set color to BboxConnectorPatch
215
+ p = BboxConnectorPatch (
216
+ bbox5 , bbox6 , loc1a = 1 , loc2a = 2 , loc1b = 4 , loc2b = 3 ,
217
+ ec = "r" , color = "g" )
218
+ p .set_clip_on (False )
219
+ ax [2 ].add_patch (p )
220
+ # set color to marked area
221
+ axins = zoomed_inset_axes (ax [2 ], 1 , loc = 1 )
222
+ axins .set_xlim (0 , 0.2 )
223
+ axins .set_ylim (0 , 0.2 )
224
+ plt .gca ().axes .get_xaxis ().set_ticks ([])
225
+ plt .gca ().axes .get_yaxis ().set_ticks ([])
226
+ mark_inset (ax [2 ], axins , loc1 = 2 , loc2 = 4 , color = "g" , ec = "0.5" )
227
+
228
+ # fill with green but color won't show if set fill to False
229
+ bbox7 = TransformedBbox (bbox , trans4 )
230
+ bbox8 = TransformedBbox (bbox , trans5 )
231
+ # BboxConnectorPatch won't show green
232
+ p = BboxConnectorPatch (
233
+ bbox7 , bbox8 , loc1a = 1 , loc2a = 2 , loc1b = 4 , loc2b = 3 ,
234
+ ec = "r" , fc = "g" , fill = False )
235
+ p .set_clip_on (False )
236
+ ax [3 ].add_patch (p )
237
+ # marked area won't show green
238
+ axins = zoomed_inset_axes (ax [3 ], 1 , loc = 1 )
239
+ axins .set_xlim (0 , 0.2 )
240
+ axins .set_ylim (0 , 0.2 )
241
+ plt .gca ().axes .get_xaxis ().set_ticks ([])
242
+ plt .gca ().axes .get_yaxis ().set_ticks ([])
243
+ mark_inset (ax [3 ], axins , loc1 = 2 , loc2 = 4 , fc = "g" , ec = "0.5" , fill = False )
244
+
245
+
158
246
@image_comparison (baseline_images = ['zoomed_axes' ,
159
247
'inverted_zoomed_axes' ],
160
248
extensions = ['png' ])
0 commit comments