Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 847e936

Browse filesBrowse files
committed
fix BboxConnectorPatch does not show facecolor #8059 and add test
1 parent c01f862 commit 847e936
Copy full SHA for 847e936

File tree

Expand file treeCollapse file tree

3 files changed

+99
-4
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+99
-4
lines changed

‎lib/mpl_toolkits/axes_grid1/inset_locator.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/axes_grid1/inset_locator.py
+10-3Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,11 @@ def __init__(self, bbox1, bbox2, loc1, loc2=None, **kwargs):
309309
raise ValueError("transform should not be set")
310310

311311
kwargs["transform"] = IdentityTransform()
312-
Patch.__init__(self, fill=False, **kwargs)
312+
if 'fill' in kwargs:
313+
Patch.__init__(self, **kwargs)
314+
else:
315+
fill = ('fc' in kwargs) or ('facecolor' in kwargs) or ('color' in kwargs)
316+
Patch.__init__(self, fill=fill, **kwargs)
313317
self.bbox1 = bbox1
314318
self.bbox2 = bbox2
315319
self.loc1 = loc1
@@ -579,8 +583,11 @@ def mark_inset(parent_axes, inset_axes, loc1, loc2, **kwargs):
579583
"""
580584
rect = TransformedBbox(inset_axes.viewLim, parent_axes.transData)
581585

582-
fill = kwargs.pop("fill", False)
583-
pp = BboxPatch(rect, fill=fill, **kwargs)
586+
if 'fill' in kwargs:
587+
pp = BboxPatch(rect, **kwargs)
588+
else:
589+
fill = ('fc' in kwargs) or ('facecolor' in kwargs) or ('color' in kwargs)
590+
pp = BboxPatch(rect, fill=fill, **kwargs)
584591
parent_axes.add_patch(pp)
585592

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

‎lib/mpl_toolkits/tests/test_axes_grid1.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/tests/test_axes_grid1.py
+89-1Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
from mpl_toolkits.axes_grid1 import host_subplot
1010
from mpl_toolkits.axes_grid1 import make_axes_locatable
1111
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
1314
from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar
1415

1516
from matplotlib.colors import LogNorm
17+
from matplotlib.transforms import Bbox, TransformedBbox, \
18+
blended_transform_factory
1619
from itertools import product
1720

1821
import numpy as np
@@ -155,6 +158,91 @@ def get_demo_image():
155158
ax.add_artist(asb)
156159

157160

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+
158246
@image_comparison(baseline_images=['zoomed_axes',
159247
'inverted_zoomed_axes'],
160248
extensions=['png'])

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.