Skip to content

Don't mark a patch transform as set if the parent transform is not set. #9426

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
Jul 8, 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
14 changes: 6 additions & 8 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ def update_from(self, other):
self._us_dashes = other._us_dashes
self.set_linewidth(other._linewidth) # also sets dash properties
self.set_transform(other.get_data_transform())
# If the transform of other needs further initialization, then it will
# be the case for this artist too.
self._transformSet = other.is_transform_set()

def get_extents(self):
"""
Expand Down Expand Up @@ -585,14 +588,9 @@ def _update(self):
if self.props is not None:
self.update(self.props)
else:
r, g, b, a = colors.to_rgba(self.patch.get_facecolor())
rho = 0.3
r = rho * r
g = rho * g
b = rho * b

self.set_facecolor((r, g, b, 0.5))
self.set_edgecolor((r, g, b, 0.5))
color = .3 * np.asarray(colors.to_rgb(self.patch.get_facecolor()))
self.set_facecolor(color)
self.set_edgecolor(color)
self.set_alpha(0.5)

def _update_transform(self, renderer):
Expand Down
39 changes: 31 additions & 8 deletions lib/matplotlib/tests/test_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
from numpy.testing import assert_almost_equal, assert_array_equal
import pytest

from matplotlib.patches import Polygon
from matplotlib.patches import Rectangle
from matplotlib.testing.decorators import image_comparison
from matplotlib.patches import Polygon, Rectangle
from matplotlib.testing.decorators import image_comparison, check_figures_equal
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
import matplotlib.collections as mcollections
from matplotlib import path as mpath
from matplotlib import transforms as mtransforms
import matplotlib.style as mstyle
from matplotlib import (
collections as mcollections, colors as mcolors, patches as mpatches,
path as mpath, style as mstyle, transforms as mtransforms)

import sys
on_win = (sys.platform == 'win32')
Expand Down Expand Up @@ -443,3 +440,29 @@ def test_contains_points():
expected = path.contains_points(points, transform, radius)
result = ell.contains_points(points)
assert np.all(result == expected)


# Currently fails with pdf/svg, probably because some parts assume a dpi of 72.
@check_figures_equal(extensions=["png"])
def test_shadow(fig_test, fig_ref):
xy = np.array([.2, .3])
dxy = np.array([.1, .2])
# We need to work around the nonsensical (dpi-dependent) interpretation of
# offsets by the Shadow class...
plt.rcParams["savefig.dpi"] = "figure"
# Test image.
a1 = fig_test.subplots()
rect = mpatches.Rectangle(xy=xy, width=.5, height=.5)
shadow = mpatches.Shadow(rect, ox=dxy[0], oy=dxy[1])
a1.add_patch(rect)
a1.add_patch(shadow)
# Reference image.
a2 = fig_ref.subplots()
rect = mpatches.Rectangle(xy=xy, width=.5, height=.5)
shadow = mpatches.Rectangle(
xy=xy + fig_ref.dpi / 72 * dxy, width=.5, height=.5,
fc=np.asarray(mcolors.to_rgb(rect.get_fc())) * .3,
ec=np.asarray(mcolors.to_rgb(rect.get_fc())) * .3,
alpha=.5)
a2.add_patch(shadow)
a2.add_patch(rect)