Skip to content

fix BboxConnectorPatch does not show facecolor #10686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/mpl_toolkits/axes_grid1/inset_locator.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,11 @@ def __init__(self, bbox1, bbox2, loc1, loc2=None, **kwargs):
raise ValueError("transform should not be set")

kwargs["transform"] = IdentityTransform()
Patch.__init__(self, fill=False, **kwargs)
if 'fill' in kwargs:
Patch.__init__(self, **kwargs)
else:
fill = ('fc' in kwargs) or ('facecolor' in kwargs) or ('color' in kwargs)
Patch.__init__(self, fill=fill, **kwargs)
self.bbox1 = bbox1
self.bbox2 = bbox2
self.loc1 = loc1
Expand Down Expand Up @@ -581,8 +585,11 @@ def mark_inset(parent_axes, inset_axes, loc1, loc2, **kwargs):
"""
rect = TransformedBbox(inset_axes.viewLim, parent_axes.transData)

fill = kwargs.pop("fill", False)
pp = BboxPatch(rect, fill=fill, **kwargs)
if 'fill' in kwargs:
pp = BboxPatch(rect, **kwargs)
else:
fill = ('fc' in kwargs) or ('facecolor' in kwargs) or ('color' in kwargs)
pp = BboxPatch(rect, fill=fill, **kwargs)
parent_axes.add_patch(pp)

p1 = BboxConnector(inset_axes.bbox, rect, loc1=loc1, **kwargs)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
85 changes: 84 additions & 1 deletion lib/mpl_toolkits/tests/test_axes_grid1.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
from mpl_toolkits.axes_grid1.inset_locator import (
zoomed_inset_axes,
mark_inset,
inset_axes
inset_axes,
BboxConnectorPatch
)
from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar

from matplotlib.colors import LogNorm
from matplotlib.transforms import Bbox, TransformedBbox, \
blended_transform_factory
from itertools import product

import numpy as np
Expand Down Expand Up @@ -226,6 +229,86 @@ def test_inset_axes_without_transform_should_use_parent_axes():
assert ax.transAxes == ax_ins.transAxes


@image_comparison(
baseline_images=['fill_facecolor'], extensions=['png'],
remove_text=True, style='mpl20')
def test_fill_facecolor():
fig, ax = plt.subplots(1, 5)
fig.set_size_inches(5, 5)
for i in range(1, 4):
ax[i].yaxis.set_visible(False)
ax[4].yaxis.tick_right()
bbox = Bbox.from_extents(0, 0.4, 1, 0.6)

# fill with blue by setting 'fc' field
bbox1 = TransformedBbox(bbox, ax[0].transData)
bbox2 = TransformedBbox(bbox, ax[1].transData)
# set color to BboxConnectorPatch
p = BboxConnectorPatch(
bbox1, bbox2, loc1a=1, loc2a=2, loc1b=4, loc2b=3,
ec="r", fc="b")
p.set_clip_on(False)
ax[0].add_patch(p)
# set color to marked area
axins = zoomed_inset_axes(ax[0], 1, loc=1)
axins.set_xlim(0, 0.2)
axins.set_ylim(0, 0.2)
plt.gca().axes.get_xaxis().set_ticks([])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to do plt.gca()? Don't you have all the Axes objects already?

plt.gca().axes.get_yaxis().set_ticks([])
mark_inset(ax[0], axins, loc1=2, loc2=4, fc="b", ec="0.5")

# fill with yellow by setting 'facecolor' field
bbox3 = TransformedBbox(bbox, ax[1].transData)
bbox4 = TransformedBbox(bbox, ax[2].transData)
# set color to BboxConnectorPatch
p = BboxConnectorPatch(
bbox3, bbox4, loc1a=1, loc2a=2, loc1b=4, loc2b=3,
ec="r", facecolor="y")
p.set_clip_on(False)
ax[1].add_patch(p)
# set color to marked area
axins = zoomed_inset_axes(ax[1], 1, loc=1)
axins.set_xlim(0, 0.2)
axins.set_ylim(0, 0.2)
plt.gca().axes.get_xaxis().set_ticks([])
plt.gca().axes.get_yaxis().set_ticks([])
mark_inset(ax[1], axins, loc1=2, loc2=4, facecolor="y", ec="0.5")

# fill with green by setting 'color' field
bbox5 = TransformedBbox(bbox, ax[2].transData)
bbox6 = TransformedBbox(bbox, ax[3].transData)
# set color to BboxConnectorPatch
p = BboxConnectorPatch(
bbox5, bbox6, loc1a=1, loc2a=2, loc1b=4, loc2b=3,
ec="r", color="g")
p.set_clip_on(False)
ax[2].add_patch(p)
# set color to marked area
axins = zoomed_inset_axes(ax[2], 1, loc=1)
axins.set_xlim(0, 0.2)
axins.set_ylim(0, 0.2)
plt.gca().axes.get_xaxis().set_ticks([])
plt.gca().axes.get_yaxis().set_ticks([])
mark_inset(ax[2], axins, loc1=2, loc2=4, color="g", ec="0.5")

# fill with green but color won't show if set fill to False
bbox7 = TransformedBbox(bbox, ax[3].transData)
bbox8 = TransformedBbox(bbox, ax[4].transData)
# BboxConnectorPatch won't show green
p = BboxConnectorPatch(
bbox7, bbox8, loc1a=1, loc2a=2, loc1b=4, loc2b=3,
ec="r", fc="g", fill=False)
p.set_clip_on(False)
ax[3].add_patch(p)
# marked area won't show green
axins = zoomed_inset_axes(ax[3], 1, loc=1)
axins.set_xlim(0, 0.2)
axins.set_ylim(0, 0.2)
axins.get_xaxis().set_ticks([])
axins.get_yaxis().set_ticks([])
mark_inset(ax[3], axins, loc1=2, loc2=4, fc="g", ec="0.5", fill=False)


@image_comparison(baseline_images=['zoomed_axes',
'inverted_zoomed_axes'],
extensions=['png'])
Expand Down