|
12 | 12 | from mpl_toolkits.axes_grid1.inset_locator import (
|
13 | 13 | zoomed_inset_axes,
|
14 | 14 | mark_inset,
|
15 |
| - inset_axes |
| 15 | + inset_axes, |
| 16 | + BboxConnectorPatch |
16 | 17 | )
|
17 | 18 | from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
|
18 | 19 |
|
19 | 20 | from matplotlib.colors import LogNorm
|
| 21 | +from matplotlib.transforms import Bbox, TransformedBbox, \ |
| 22 | + blended_transform_factory |
20 | 23 | from itertools import product
|
21 | 24 |
|
22 | 25 | import numpy as np
|
@@ -226,6 +229,91 @@ def test_inset_axes_without_transform_should_use_parent_axes():
|
226 | 229 | assert ax.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 | +def test_fill_facecolor(): |
| 236 | + fig, ax = plt.subplots(1, 5) |
| 237 | + fig.set_size_inches(5, 5) |
| 238 | + trans1 = blended_transform_factory(ax[0].transData, ax[0].transData) |
| 239 | + trans2 = blended_transform_factory(ax[1].transData, ax[1].transData) |
| 240 | + trans3 = blended_transform_factory(ax[2].transData, ax[2].transData) |
| 241 | + trans4 = blended_transform_factory(ax[3].transData, ax[3].transData) |
| 242 | + trans5 = blended_transform_factory(ax[4].transData, ax[4].transData) |
| 243 | + for i in range(1, 4): |
| 244 | + ax[i].yaxis.set_visible(False) |
| 245 | + ax[4].yaxis.tick_right() |
| 246 | + bbox = Bbox.from_extents(0, 0.4, 1, 0.6) |
| 247 | + |
| 248 | + # fill with blue by setting 'fc' field |
| 249 | + bbox1 = TransformedBbox(bbox, trans1) |
| 250 | + bbox2 = TransformedBbox(bbox, trans2) |
| 251 | + # set color to BboxConnectorPatch |
| 252 | + p = BboxConnectorPatch( |
| 253 | + bbox1, bbox2, loc1a=1, loc2a=2, loc1b=4, loc2b=3, |
| 254 | + ec="r", fc="b") |
| 255 | + p.set_clip_on(False) |
| 256 | + ax[0].add_patch(p) |
| 257 | + # set color to marked area |
| 258 | + axins = zoomed_inset_axes(ax[0], 1, loc=1) |
| 259 | + axins.set_xlim(0, 0.2) |
| 260 | + axins.set_ylim(0, 0.2) |
| 261 | + plt.gca().axes.get_xaxis().set_ticks([]) |
| 262 | + plt.gca().axes.get_yaxis().set_ticks([]) |
| 263 | + mark_inset(ax[0], axins, loc1=2, loc2=4, fc="b", ec="0.5") |
| 264 | + |
| 265 | + # fill with yellow by setting 'facecolor' field |
| 266 | + bbox3 = TransformedBbox(bbox, trans2) |
| 267 | + bbox4 = TransformedBbox(bbox, trans3) |
| 268 | + # set color to BboxConnectorPatch |
| 269 | + p = BboxConnectorPatch( |
| 270 | + bbox3, bbox4, loc1a=1, loc2a=2, loc1b=4, loc2b=3, |
| 271 | + ec="r", facecolor="y") |
| 272 | + p.set_clip_on(False) |
| 273 | + ax[1].add_patch(p) |
| 274 | + # set color to marked area |
| 275 | + axins = zoomed_inset_axes(ax[1], 1, loc=1) |
| 276 | + axins.set_xlim(0, 0.2) |
| 277 | + axins.set_ylim(0, 0.2) |
| 278 | + plt.gca().axes.get_xaxis().set_ticks([]) |
| 279 | + plt.gca().axes.get_yaxis().set_ticks([]) |
| 280 | + mark_inset(ax[1], axins, loc1=2, loc2=4, facecolor="y", ec="0.5") |
| 281 | + |
| 282 | + # fill with green by setting 'color' field |
| 283 | + bbox5 = TransformedBbox(bbox, trans3) |
| 284 | + bbox6 = TransformedBbox(bbox, trans4) |
| 285 | + # set color to BboxConnectorPatch |
| 286 | + p = BboxConnectorPatch( |
| 287 | + bbox5, bbox6, loc1a=1, loc2a=2, loc1b=4, loc2b=3, |
| 288 | + ec="r", color="g") |
| 289 | + p.set_clip_on(False) |
| 290 | + ax[2].add_patch(p) |
| 291 | + # set color to marked area |
| 292 | + axins = zoomed_inset_axes(ax[2], 1, loc=1) |
| 293 | + axins.set_xlim(0, 0.2) |
| 294 | + axins.set_ylim(0, 0.2) |
| 295 | + plt.gca().axes.get_xaxis().set_ticks([]) |
| 296 | + plt.gca().axes.get_yaxis().set_ticks([]) |
| 297 | + mark_inset(ax[2], axins, loc1=2, loc2=4, color="g", ec="0.5") |
| 298 | + |
| 299 | + # fill with green but color won't show if set fill to False |
| 300 | + bbox7 = TransformedBbox(bbox, trans4) |
| 301 | + bbox8 = TransformedBbox(bbox, trans5) |
| 302 | + # BboxConnectorPatch won't show green |
| 303 | + p = BboxConnectorPatch( |
| 304 | + bbox7, bbox8, loc1a=1, loc2a=2, loc1b=4, loc2b=3, |
| 305 | + ec="r", fc="g", fill=False) |
| 306 | + p.set_clip_on(False) |
| 307 | + ax[3].add_patch(p) |
| 308 | + # marked area won't show green |
| 309 | + axins = zoomed_inset_axes(ax[3], 1, loc=1) |
| 310 | + axins.set_xlim(0, 0.2) |
| 311 | + axins.set_ylim(0, 0.2) |
| 312 | + plt.gca().axes.get_xaxis().set_ticks([]) |
| 313 | + plt.gca().axes.get_yaxis().set_ticks([]) |
| 314 | + mark_inset(ax[3], axins, loc1=2, loc2=4, fc="g", ec="0.5", fill=False) |
| 315 | + |
| 316 | + |
229 | 317 | @image_comparison(baseline_images=['zoomed_axes',
|
230 | 318 | 'inverted_zoomed_axes'],
|
231 | 319 | extensions=['png'])
|
|
0 commit comments