Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 384e492

Browse files
committed
Merge pull request matplotlib#1265 from pelson/contour_limits
Fixed pre-transform limit calculation bug for contour sets.
2 parents e546aef + e64a428 commit 384e492

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

lib/matplotlib/contour.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,7 @@ def _process_args(self, *args, **kwargs):
946946
min = seg.min(axis=0)
947947
max = seg.max(axis=0)
948948
havelimits = True
949+
949950
if havelimits:
950951
self.ax.update_datalim([min, max])
951952
self.ax.autoscale_view(tight=True)
@@ -1291,17 +1292,31 @@ def _process_args(self, *args, **kwargs):
12911292
self.zmax = args[0].zmax
12921293
else:
12931294
x, y, z = self._contour_args(args, kwargs)
1294-
1295+
1296+
_mask = ma.getmask(z)
1297+
if _mask is ma.nomask:
1298+
_mask = None
1299+
C = _cntr.Cntr(x, y, z.filled(), _mask)
1300+
1301+
t = self.ax.transData if self.transform is None else self.transform
1302+
1303+
# if the transform is not trans data, and some part of it
1304+
# contains transData, transform the xs and ys to data coordinates
1305+
if (t != self.ax.transData and
1306+
any(t.contains_branch_seperately(self.ax.transData))):
1307+
trans_to_data = self.transform - self.ax.transData
1308+
pts = (np.vstack([x.flat, y.flat]).T)
1309+
transformed_pts = trans_to_data.transform(pts)
1310+
x = transformed_pts[..., 0]
1311+
y = transformed_pts[..., 1]
1312+
12951313
x0 = ma.minimum(x)
12961314
x1 = ma.maximum(x)
12971315
y0 = ma.minimum(y)
12981316
y1 = ma.maximum(y)
12991317
self.ax.update_datalim([(x0,y0), (x1,y1)])
13001318
self.ax.autoscale_view(tight=True)
1301-
_mask = ma.getmask(z)
1302-
if _mask is ma.nomask:
1303-
_mask = None
1304-
C = _cntr.Cntr(x, y, z.filled(), _mask)
1319+
13051320
self.Cntr = C
13061321

13071322
def _get_allsegs_and_allkinds(self):

lib/matplotlib/tests/test_transforms.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import matplotlib.patches as mpatches
1717

1818

19-
2019
@cleanup
2120
def test_non_affine_caching():
2221
class AssertingNonAffineTransform(mtrans.Transform):
@@ -108,6 +107,17 @@ def test_pre_transform_plotting():
108107
ax.quiver(x, y + 5, u, v, transform=times10 + ax.transData)
109108

110109
ax.barbs(x - 3, y + 5, u**2, v**2, transform=times10 + ax.transData)
110+
111+
112+
@cleanup
113+
def test_contour_pre_transform_limits():
114+
ax = plt.axes()
115+
xs, ys = np.meshgrid(np.linspace(15, 20, 15), np.linspace(12.4, 12.5, 20))
116+
ax.contourf(xs, ys, np.log(xs * ys), transform=mtrans.Affine2D().scale(0.1) + ax.transData)
117+
118+
expected = np.array([[ 1.5 , 1.24],
119+
[ 2. , 1.25]])
120+
assert_almost_equal(expected, ax.dataLim.get_points())
111121

112122

113123
def test_Affine2D_from_values():

0 commit comments

Comments
 (0)