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 f8f14d7

Browse filesBrowse files
authored
Merge pull request #10686 from CinnyCao/becky-fix-#8059
fix BboxConnectorPatch does not show facecolor
2 parents 186b3b3 + c7aba6b commit f8f14d7
Copy full SHA for f8f14d7

File tree

Expand file treeCollapse file tree

3 files changed

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

3 files changed

+94
-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
@@ -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)
Loading

‎lib/mpl_toolkits/tests/test_axes_grid1.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/tests/test_axes_grid1.py
+84-1Lines changed: 84 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,86 @@ 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+
for i in range(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+
229312
@image_comparison(baseline_images=['zoomed_axes',
230313
'inverted_zoomed_axes'],
231314
extensions=['png'])

0 commit comments

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