Skip to content
This repository

Fixed pre-transform limit calculation bug for contour sets. #1265

Merged
merged 1 commit into from over 1 year ago

2 participants

Phil Elson Michael Droettboom
Phil Elson
Collaborator

This is a bug fix to calculate the limits of a ContourSets using pre-transforms appropriately (see test) which I missed in #1090.

As well as this, I intend to write a MEP to unify and simplify the limit/view calculations for all artists on an axes for future mpl versions.

Michael Droettboom mdboom merged commit 384e492 into from September 18, 2012
Michael Droettboom mdboom closed this September 18, 2012
Byron Blay bblay referenced this pull request in SciTools/iris September 24, 2012
Closed

cartopy replaces basemap #67

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Sep 17, 2012
Phil Elson Fixed pre-transform limit calculation bug for contour sets. e64a428
This page is out of date. Refresh to see the latest.
25  lib/matplotlib/contour.py
@@ -946,6 +946,7 @@ def _process_args(self, *args, **kwargs):
946 946
                     min = seg.min(axis=0)
947 947
                     max = seg.max(axis=0)
948 948
                     havelimits = True
  949
+        
949 950
         if havelimits:
950 951
             self.ax.update_datalim([min, max])
951 952
             self.ax.autoscale_view(tight=True)
@@ -1291,17 +1292,31 @@ def _process_args(self, *args, **kwargs):
1291 1292
             self.zmax = args[0].zmax
1292 1293
         else:
1293 1294
             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
+            
1295 1313
             x0 = ma.minimum(x)
1296 1314
             x1 = ma.maximum(x)
1297 1315
             y0 = ma.minimum(y)
1298 1316
             y1 = ma.maximum(y)
1299 1317
             self.ax.update_datalim([(x0,y0), (x1,y1)])
1300 1318
             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
+
1305 1320
         self.Cntr = C
1306 1321
 
1307 1322
     def _get_allsegs_and_allkinds(self):
12  lib/matplotlib/tests/test_transforms.py
@@ -16,7 +16,6 @@
16 16
 import matplotlib.patches as mpatches
17 17
 
18 18
 
19  
-
20 19
 @cleanup
21 20
 def test_non_affine_caching():
22 21
     class AssertingNonAffineTransform(mtrans.Transform):
@@ -108,6 +107,17 @@ def test_pre_transform_plotting():
108 107
     ax.quiver(x, y + 5, u, v, transform=times10 + ax.transData)
109 108
     
110 109
     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())
111 121
     
112 122
 
113 123
 def test_Affine2D_from_values():
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.