|
12 | 12 | frommpl_toolkits.axes_grid1.inset_locatorimport (
|
13 | 13 | zoomed_inset_axes,
|
14 | 14 | mark_inset,
|
15 |
| -inset_axes |
| 15 | +inset_axes, |
| 16 | +BboxConnectorPatch |
16 | 17 | )
|
17 | 18 | frommpl_toolkits.axes_grid1.anchored_artistsimportAnchoredSizeBar
|
18 | 19 |
|
19 | 20 | frommatplotlib.colorsimportLogNorm
|
| 21 | +frommatplotlib.transformsimportBbox,TransformedBbox, \ |
| 22 | +blended_transform_factory |
20 | 23 | fromitertoolsimportproduct
|
21 | 24 |
|
22 | 25 | importnumpyasnp
|
@@ -226,6 +229,86 @@ def test_inset_axes_without_transform_should_use_parent_axes():
|
226 | 229 | assertax.transAxes==ax_ins.transAxes
|
227 | 230 |
|
228 | 231 |
|
| 232 | +@image_comparison( |
| 233 | +baseline_images=['fill_facecolor'],extensions=['png'], |
| 234 | +remove_text=True,style='mpl20') |
| 235 | +deftest_fill_facecolor(): |
| 236 | +fig,ax=plt.subplots(1,5) |
| 237 | +fig.set_size_inches(5,5) |
| 238 | +foriinrange(1,4): |
| 239 | +ax[i].yaxis.set_visible(False) |
| 240 | +ax[4].yaxis.tick_right() |
| 241 | +bbox=Bbox.from_extents(0,0.4,1,0.6) |
| 242 | + |
| 243 | +# fill with blue by setting 'fc' field |
| 244 | +bbox1=TransformedBbox(bbox,ax[0].transData) |
| 245 | +bbox2=TransformedBbox(bbox,ax[1].transData) |
| 246 | +# set color to BboxConnectorPatch |
| 247 | +p=BboxConnectorPatch( |
| 248 | +bbox1,bbox2,loc1a=1,loc2a=2,loc1b=4,loc2b=3, |
| 249 | +ec="r",fc="b") |
| 250 | +p.set_clip_on(False) |
| 251 | +ax[0].add_patch(p) |
| 252 | +# set color to marked area |
| 253 | +axins=zoomed_inset_axes(ax[0],1,loc=1) |
| 254 | +axins.set_xlim(0,0.2) |
| 255 | +axins.set_ylim(0,0.2) |
| 256 | +plt.gca().axes.get_xaxis().set_ticks([]) |
| 257 | +plt.gca().axes.get_yaxis().set_ticks([]) |
| 258 | +mark_inset(ax[0],axins,loc1=2,loc2=4,fc="b",ec="0.5") |
| 259 | + |
| 260 | +# fill with yellow by setting 'facecolor' field |
| 261 | +bbox3=TransformedBbox(bbox,ax[1].transData) |
| 262 | +bbox4=TransformedBbox(bbox,ax[2].transData) |
| 263 | +# set color to BboxConnectorPatch |
| 264 | +p=BboxConnectorPatch( |
| 265 | +bbox3,bbox4,loc1a=1,loc2a=2,loc1b=4,loc2b=3, |
| 266 | +ec="r",facecolor="y") |
| 267 | +p.set_clip_on(False) |
| 268 | +ax[1].add_patch(p) |
| 269 | +# set color to marked area |
| 270 | +axins=zoomed_inset_axes(ax[1],1,loc=1) |
| 271 | +axins.set_xlim(0,0.2) |
| 272 | +axins.set_ylim(0,0.2) |
| 273 | +plt.gca().axes.get_xaxis().set_ticks([]) |
| 274 | +plt.gca().axes.get_yaxis().set_ticks([]) |
| 275 | +mark_inset(ax[1],axins,loc1=2,loc2=4,facecolor="y",ec="0.5") |
| 276 | + |
| 277 | +# fill with green by setting 'color' field |
| 278 | +bbox5=TransformedBbox(bbox,ax[2].transData) |
| 279 | +bbox6=TransformedBbox(bbox,ax[3].transData) |
| 280 | +# set color to BboxConnectorPatch |
| 281 | +p=BboxConnectorPatch( |
| 282 | +bbox5,bbox6,loc1a=1,loc2a=2,loc1b=4,loc2b=3, |
| 283 | +ec="r",color="g") |
| 284 | +p.set_clip_on(False) |
| 285 | +ax[2].add_patch(p) |
| 286 | +# set color to marked area |
| 287 | +axins=zoomed_inset_axes(ax[2],1,loc=1) |
| 288 | +axins.set_xlim(0,0.2) |
| 289 | +axins.set_ylim(0,0.2) |
| 290 | +plt.gca().axes.get_xaxis().set_ticks([]) |
| 291 | +plt.gca().axes.get_yaxis().set_ticks([]) |
| 292 | +mark_inset(ax[2],axins,loc1=2,loc2=4,color="g",ec="0.5") |
| 293 | + |
| 294 | +# fill with green but color won't show if set fill to False |
| 295 | +bbox7=TransformedBbox(bbox,ax[3].transData) |
| 296 | +bbox8=TransformedBbox(bbox,ax[4].transData) |
| 297 | +# BboxConnectorPatch won't show green |
| 298 | +p=BboxConnectorPatch( |
| 299 | +bbox7,bbox8,loc1a=1,loc2a=2,loc1b=4,loc2b=3, |
| 300 | +ec="r",fc="g",fill=False) |
| 301 | +p.set_clip_on(False) |
| 302 | +ax[3].add_patch(p) |
| 303 | +# marked area won't show green |
| 304 | +axins=zoomed_inset_axes(ax[3],1,loc=1) |
| 305 | +axins.set_xlim(0,0.2) |
| 306 | +axins.set_ylim(0,0.2) |
| 307 | +axins.get_xaxis().set_ticks([]) |
| 308 | +axins.get_yaxis().set_ticks([]) |
| 309 | +mark_inset(ax[3],axins,loc1=2,loc2=4,fc="g",ec="0.5",fill=False) |
| 310 | + |
| 311 | + |
229 | 312 | @image_comparison(baseline_images=['zoomed_axes',
|
230 | 313 | 'inverted_zoomed_axes'],
|
231 | 314 | extensions=['png'])
|
|