Skip to content

Commit 8e15b70

Browse files
committed
fix BboxConnectorPatch does not show facecolor #8059 and add test
1 parent cc7d086 commit 8e15b70

File tree

3 files changed

+99
-4
lines changed

3 files changed

+99
-4
lines changed

lib/mpl_toolkits/axes_grid1/inset_locator.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,11 @@ def __init__(self, bbox1, bbox2, loc1, loc2=None, **kwargs):
308308
raise ValueError("transform should not be set")
309309

310310
kwargs["transform"] = IdentityTransform()
311-
Patch.__init__(self, fill=False, **kwargs)
311+
if 'fill' in kwargs:
312+
Patch.__init__(self, **kwargs)
313+
else:
314+
fill = ('fc' in kwargs) or ('facecolor' in kwargs) or ('color' in kwargs)
315+
Patch.__init__(self, fill=fill, **kwargs)
312316
self.bbox1 = bbox1
313317
self.bbox2 = bbox2
314318
self.loc1 = loc1
@@ -581,8 +585,11 @@ def mark_inset(parent_axes, inset_axes, loc1, loc2, **kwargs):
581585
"""
582586
rect = TransformedBbox(inset_axes.viewLim, parent_axes.transData)
583587

584-
fill = kwargs.pop("fill", False)
585-
pp = BboxPatch(rect, fill=fill, **kwargs)
588+
if 'fill' in kwargs:
589+
pp = BboxPatch(rect, **kwargs)
590+
else:
591+
fill = ('fc' in kwargs) or ('facecolor' in kwargs) or ('color' in kwargs)
592+
pp = BboxPatch(rect, fill=fill, **kwargs)
586593
parent_axes.add_patch(pp)
587594

588595
p1 = BboxConnector(inset_axes.bbox, rect, loc1=loc1, **kwargs)

lib/mpl_toolkits/tests/test_axes_grid1.py

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
from mpl_toolkits.axes_grid1.inset_locator import (
1313
zoomed_inset_axes,
1414
mark_inset,
15-
inset_axes
15+
inset_axes,
16+
BboxConnectorPatch
1617
)
1718
from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
1819

1920
from matplotlib.colors import LogNorm
21+
from matplotlib.transforms import Bbox, TransformedBbox, \
22+
blended_transform_factory
2023
from itertools import product
2124

2225
import numpy as np
@@ -226,6 +229,91 @@ def test_inset_axes_without_transform_should_use_parent_axes():
226229
assert ax.transAxes == ax_ins.transAxes
227230

228231

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+
229317
@image_comparison(baseline_images=['zoomed_axes',
230318
'inverted_zoomed_axes'],
231319
extensions=['png'])

0 commit comments

Comments
 (0)