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

Skip to content

Commit b96e139

Browse files
committed
Removed the use of x_isdata and y_isdata and tidied up transfoms a little.
1 parent 83ed6c8 commit b96e139

File tree

7 files changed

+176
-42
lines changed

7 files changed

+176
-42
lines changed

doc/api/api_changes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ Changes in 1.2.x
7272
original keyword arguments will override any value provided by
7373
*capthick*.
7474

75+
* Aritsts no longer have ``x_isdata`` or ``y_isdata`` attributes. Instead
76+
any artist's transform can be interrogated with
77+
``artist_instance.get_transform().is_data(ax.transData)``
78+
7579
Changes in 1.1.x
7680
================
7781

lib/matplotlib/artist.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ def __init__(self):
101101
self._remove_method = None
102102
self._url = None
103103
self._gid = None
104-
self.x_isdata = True # False to avoid updating Axes.dataLim with x
105-
self.y_isdata = True # with y
106104
self._snap = None
107105

108106
def remove(self):

lib/matplotlib/axes.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,7 @@ def _update_line_limits(self, line):
14771477
if line_trans == self.transData:
14781478
data_path = path
14791479

1480-
elif line_trans.contains_branch(self.transData):
1480+
elif any(line_trans.contains_branch_seperately(self.transData)):
14811481
# identify the transform to go from line's coordinates
14821482
# to data coordinates
14831483
trans_to_data = line_trans - self.transData
@@ -1491,7 +1491,7 @@ def _update_line_limits(self, line):
14911491
data_path = trans_to_data.transform_path_affine(na_path)
14921492
else:
14931493
data_path = trans_to_data.transform_path(path)
1494-
else:
1494+
else:
14951495
# for backwards compatibility we update the dataLim with the
14961496
# coordinate range of the given path, even though the coordinate
14971497
# systems are completely different. This may occur in situations
@@ -1500,10 +1500,13 @@ def _update_line_limits(self, line):
15001500
data_path = path
15011501

15021502
if data_path.vertices.size > 0:
1503-
self.dataLim.update_from_path(data_path,
1503+
updatex, updatey = line_trans.contains_branch_seperately(
1504+
self.transData
1505+
)
1506+
self.dataLim.update_from_path(data_path,
15041507
self.ignore_existing_data_limits,
1505-
updatex=line.x_isdata,
1506-
updatey=line.y_isdata)
1508+
updatex=updatex,
1509+
updatey=updatey)
15071510
self.ignore_existing_data_limits = False
15081511

15091512
def add_patch(self, p):
@@ -1539,11 +1542,14 @@ def _update_patch_limits(self, patch):
15391542
if vertices.size > 0:
15401543
xys = patch.get_patch_transform().transform(vertices)
15411544
if patch.get_data_transform() != self.transData:
1542-
transform = (patch.get_data_transform() +
1543-
self.transData.inverted())
1544-
xys = transform.transform(xys)
1545-
self.update_datalim(xys, updatex=patch.x_isdata,
1546-
updatey=patch.y_isdata)
1545+
patch_to_data = (patch.get_data_transform() -
1546+
self.transData)
1547+
xys = patch_to_data.transform(xys)
1548+
1549+
updatex, updatey = patch.get_transform().\
1550+
contains_branch_seperately(self.transData)
1551+
self.update_datalim(xys, updatex=updatex,
1552+
updatey=updatey)
15471553

15481554

15491555
def add_table(self, tab):
@@ -1631,13 +1637,13 @@ def _process_unit_info(self, xdata=None, ydata=None, kwargs=None):
16311637
if xdata is not None:
16321638
# we only need to update if there is nothing set yet.
16331639
if not self.xaxis.have_units():
1634-
self.xaxis.update_units(xdata)
1640+
self.xaxis.update_units(xdata)
16351641
#print '\tset from xdata', self.xaxis.units
16361642

16371643
if ydata is not None:
16381644
# we only need to update if there is nothing set yet.
16391645
if not self.yaxis.have_units():
1640-
self.yaxis.update_units(ydata)
1646+
self.yaxis.update_units(ydata)
16411647
#print '\tset from ydata', self.yaxis.units
16421648

16431649
# process kwargs 2nd since these will override default units
@@ -3456,7 +3462,6 @@ def axhline(self, y=0, xmin=0, xmax=1, **kwargs):
34563462
trans = mtransforms.blended_transform_factory(
34573463
self.transAxes, self.transData)
34583464
l = mlines.Line2D([xmin,xmax], [y,y], transform=trans, **kwargs)
3459-
l.x_isdata = False
34603465
self.add_line(l)
34613466
self.autoscale_view(scalex=False, scaley=scaley)
34623467
return l
@@ -3521,7 +3526,6 @@ def axvline(self, x=0, ymin=0, ymax=1, **kwargs):
35213526
trans = mtransforms.blended_transform_factory(
35223527
self.transData, self.transAxes)
35233528
l = mlines.Line2D([x,x], [ymin,ymax] , transform=trans, **kwargs)
3524-
l.y_isdata = False
35253529
self.add_line(l)
35263530
self.autoscale_view(scalex=scalex, scaley=False)
35273531
return l
@@ -3578,7 +3582,6 @@ def axhspan(self, ymin, ymax, xmin=0, xmax=1, **kwargs):
35783582
verts = (xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)
35793583
p = mpatches.Polygon(verts, **kwargs)
35803584
p.set_transform(trans)
3581-
p.x_isdata = False
35823585
self.add_patch(p)
35833586
self.autoscale_view(scalex=False)
35843587
return p
@@ -3635,7 +3638,6 @@ def axvspan(self, xmin, xmax, ymin=0, ymax=1, **kwargs):
36353638
verts = [(xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)]
36363639
p = mpatches.Polygon(verts, **kwargs)
36373640
p.set_transform(trans)
3638-
p.y_isdata = False
36393641
self.add_patch(p)
36403642
self.autoscale_view(scaley=False)
36413643
return p

lib/matplotlib/lines.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
# TODO: expose cap and join style attrs
77
from __future__ import division, print_function
88

9+
import warnings
10+
911
import numpy as np
1012
from numpy import ma
1113
from matplotlib import verbose
@@ -256,8 +258,8 @@ def contains(self, mouseevent):
256258
yt = xy[:, 1]
257259

258260
# Convert pick radius from points to pixels
259-
if self.figure == None:
260-
warning.warn('no figure set when check if mouse is on line')
261+
if self.figure is None:
262+
warnings.warn('no figure set when check if mouse is on line')
261263
pixels = self.pickradius
262264
else:
263265
pixels = self.figure.dpi/72. * self.pickradius

lib/matplotlib/patches.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,15 @@ def get_transform(self):
167167
return self.get_patch_transform() + artist.Artist.get_transform(self)
168168

169169
def get_data_transform(self):
170+
"""
171+
Return the :class:`~matplotlib.transforms.Transform` ... I'm not sure
172+
"""
170173
return artist.Artist.get_transform(self)
171174

172175
def get_patch_transform(self):
176+
"""
177+
Return the :class:`~matplotlib.transforms.Transform` ... I'm not sure
178+
"""
173179
return transforms.IdentityTransform()
174180

175181
def get_antialiased(self):

lib/matplotlib/tests/test_transforms.py

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import unittest
33

44
from nose.tools import assert_equal
5-
import numpy.testing as np_test, assert_almost_equal
5+
import numpy.testing as np_test
6+
from numpy.testing import assert_almost_equal
67
from matplotlib.transforms import Affine2D, BlendedGenericTransform
78
from matplotlib.path import Path
89
from matplotlib.scale import LogScale
@@ -213,6 +214,11 @@ def setUp(self):
213214
# self.stack1.write_graphviz(file('stack1.dot', 'w'))
214215
# self.stack2.write_graphviz(file('stack2.dot', 'w'))
215216
# self.stack2_subset.write_graphviz(file('stack2_subset.dot', 'w'))
217+
218+
def test_transform_depth(self):
219+
assert_equal(self.stack1.depth, 4)
220+
assert_equal(self.stack2.depth, 4)
221+
assert_equal(self.stack2_subset.depth, 3)
216222

217223
def test_left_to_right_iteration(self):
218224
stack3 = (self.ta1 + (self.tn1 + (self.ta2 + self.tn2))) + self.ta3
@@ -224,7 +230,7 @@ def test_left_to_right_iteration(self):
224230
self.tn2 + self.ta3,
225231
self.ta3,
226232
]
227-
r = [rh for lh, rh in stack3._iter_break_from_left_to_right()]
233+
r = [rh for _, rh in stack3._iter_break_from_left_to_right()]
228234
self.assertEqual(len(r), len(target_transforms))
229235

230236
for target_stack, stack in zip(target_transforms, r):
@@ -236,8 +242,11 @@ def test_transform_shortcuts(self):
236242

237243
# check that we cannot find a chain from the subset back to the superset
238244
# (since the inverse of the Transform is not defined.)
239-
self.assertRaises(ValueError, self.stack2_subset.__sub__, self.stack2)
240-
self.assertRaises(ValueError, self.stack1.__sub__, self.stack2)
245+
with self.assertRaises(ValueError):
246+
self.stack2_subset - self.stack2
247+
248+
with self.assertRaises(ValueError):
249+
self.stack1 - self.stack2
241250

242251
aff1 = self.ta1 + (self.ta2 + self.ta3)
243252
aff2 = self.ta2 + self.ta3
@@ -312,6 +321,42 @@ def test_affine_simplification(self):
312321
class TestTransformPlotInterface(unittest.TestCase):
313322
def tearDown(self):
314323
plt.close()
324+
325+
def test_line_extent_axes_coords(self):
326+
# a simple line in axes coordinates
327+
ax = plt.axes()
328+
ax.plot([0.1, 1.2, 0.8], [0.9, 0.5, 0.8], transform=ax.transAxes)
329+
np.testing.assert_array_equal(ax.dataLim.get_points(), np.array([[0, 0], [1, 1]]))
330+
331+
def test_line_extent_data_coords(self):
332+
# a simple line in data coordinates
333+
ax = plt.axes()
334+
ax.plot([0.1, 1.2, 0.8], [0.9, 0.5, 0.8], transform=ax.transData)
335+
np.testing.assert_array_equal(ax.dataLim.get_points(), np.array([[ 0.1, 0.5], [ 1.2, 0.9]]))
336+
337+
def test_line_extent_compound_coords1(self):
338+
# a simple line in data coordinates in the y component, and in axes coordinates in the x
339+
ax = plt.axes()
340+
trans = mtrans.blended_transform_factory(ax.transAxes, ax.transData)
341+
ax.plot([0.1, 1.2, 0.8], [35, -5, 18], transform=trans)
342+
np.testing.assert_array_equal(ax.dataLim.get_points(), np.array([[ 0., -5.], [ 1., 35.]]))
343+
plt.close()
344+
345+
def test_line_extent_predata_transform_coords(self):
346+
# a simple line in (offset + data) coordinates
347+
ax = plt.axes()
348+
trans = mtrans.Affine2D().scale(10) + ax.transData
349+
ax.plot([0.1, 1.2, 0.8], [35, -5, 18], transform=trans)
350+
np.testing.assert_array_equal(ax.dataLim.get_points(), np.array([[1., -50.], [12., 350.]]))
351+
plt.close()
352+
353+
def test_line_extent_compound_coords2(self):
354+
# a simple line in (offset + data) coordinates in the y component, and in axes coordinates in the x
355+
ax = plt.axes()
356+
trans = mtrans.blended_transform_factory(ax.transAxes, mtrans.Affine2D().scale(10) + ax.transData)
357+
ax.plot([0.1, 1.2, 0.8], [35, -5, 18], transform=trans)
358+
np.testing.assert_array_equal(ax.dataLim.get_points(), np.array([[ 0., -50.], [ 1., 350.]]))
359+
plt.close()
315360

316361
def test_line_extents_affine(self):
317362
ax = plt.axes()
@@ -362,10 +407,10 @@ def test_line_extents_for_non_affine_transData(self):
362407
# before a transData transformation, hence the data limits
363408
# are not what is being shown on the actual plot.
364409
expeted_data_lim = np.array([[0., 0.], [9., 9.]]) + [0, 10]
365-
np.testing.assert_array_almost_equal(ax.dataLim.get_points(),
410+
np.testing.assert_array_almost_equal(ax.dataLim.get_points(),
366411
expeted_data_lim)
367412

368413

369414
if __name__=='__main__':
370415
import nose
371-
nose.runmodule(argv=['-s','--with-doctest'], exit=False)
416+
nose.runmodule(argv=['-s','--with-doctest'], exit=False)

0 commit comments

Comments
 (0)