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

Skip to content
Merged
Prev Previous commit
Next Next commit
Removed the use of x_isdata and y_isdata and tidied up transfoms a li…
…ttle.
  • Loading branch information
pelson committed Aug 20, 2012
commit b96e13988290f3d29cf26953bd29a7d9b456b446
4 changes: 4 additions & 0 deletions doc/api/api_changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ Changes in 1.2.x
original keyword arguments will override any value provided by
*capthick*.

* Aritsts no longer have ``x_isdata`` or ``y_isdata`` attributes. Instead
any artist's transform can be interrogated with
``artist_instance.get_transform().is_data(ax.transData)``

Changes in 1.1.x
================

Expand Down
2 changes: 0 additions & 2 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ def __init__(self):
self._remove_method = None
self._url = None
self._gid = None
self.x_isdata = True # False to avoid updating Axes.dataLim with x
self.y_isdata = True # with y
self._snap = None

def remove(self):
Expand Down
34 changes: 18 additions & 16 deletions lib/matplotlib/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,7 @@ def _update_line_limits(self, line):
if line_trans == self.transData:
data_path = path

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

if data_path.vertices.size > 0:
self.dataLim.update_from_path(data_path,
updatex, updatey = line_trans.contains_branch_seperately(
self.transData
)
self.dataLim.update_from_path(data_path,
self.ignore_existing_data_limits,
updatex=line.x_isdata,
updatey=line.y_isdata)
updatex=updatex,
updatey=updatey)
self.ignore_existing_data_limits = False

def add_patch(self, p):
Expand Down Expand Up @@ -1539,11 +1542,14 @@ def _update_patch_limits(self, patch):
if vertices.size > 0:
xys = patch.get_patch_transform().transform(vertices)
if patch.get_data_transform() != self.transData:
transform = (patch.get_data_transform() +
self.transData.inverted())
xys = transform.transform(xys)
self.update_datalim(xys, updatex=patch.x_isdata,
updatey=patch.y_isdata)
patch_to_data = (patch.get_data_transform() -
self.transData)
xys = patch_to_data.transform(xys)

updatex, updatey = patch.get_transform().\
contains_branch_seperately(self.transData)
self.update_datalim(xys, updatex=updatex,
updatey=updatey)


def add_table(self, tab):
Expand Down Expand Up @@ -1631,13 +1637,13 @@ def _process_unit_info(self, xdata=None, ydata=None, kwargs=None):
if xdata is not None:
# we only need to update if there is nothing set yet.
if not self.xaxis.have_units():
self.xaxis.update_units(xdata)
self.xaxis.update_units(xdata)
#print '\tset from xdata', self.xaxis.units

if ydata is not None:
# we only need to update if there is nothing set yet.
if not self.yaxis.have_units():
self.yaxis.update_units(ydata)
self.yaxis.update_units(ydata)
#print '\tset from ydata', self.yaxis.units

# process kwargs 2nd since these will override default units
Expand Down Expand Up @@ -3456,7 +3462,6 @@ def axhline(self, y=0, xmin=0, xmax=1, **kwargs):
trans = mtransforms.blended_transform_factory(
self.transAxes, self.transData)
l = mlines.Line2D([xmin,xmax], [y,y], transform=trans, **kwargs)
l.x_isdata = False
self.add_line(l)
self.autoscale_view(scalex=False, scaley=scaley)
return l
Expand Down Expand Up @@ -3521,7 +3526,6 @@ def axvline(self, x=0, ymin=0, ymax=1, **kwargs):
trans = mtransforms.blended_transform_factory(
self.transData, self.transAxes)
l = mlines.Line2D([x,x], [ymin,ymax] , transform=trans, **kwargs)
l.y_isdata = False
self.add_line(l)
self.autoscale_view(scalex=scalex, scaley=False)
return l
Expand Down Expand Up @@ -3578,7 +3582,6 @@ def axhspan(self, ymin, ymax, xmin=0, xmax=1, **kwargs):
verts = (xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)
p = mpatches.Polygon(verts, **kwargs)
p.set_transform(trans)
p.x_isdata = False
self.add_patch(p)
self.autoscale_view(scalex=False)
return p
Expand Down Expand Up @@ -3635,7 +3638,6 @@ def axvspan(self, xmin, xmax, ymin=0, ymax=1, **kwargs):
verts = [(xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)]
p = mpatches.Polygon(verts, **kwargs)
p.set_transform(trans)
p.y_isdata = False
self.add_patch(p)
self.autoscale_view(scaley=False)
return p
Expand Down
6 changes: 4 additions & 2 deletions lib/matplotlib/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# TODO: expose cap and join style attrs
from __future__ import division, print_function

import warnings

import numpy as np
from numpy import ma
from matplotlib import verbose
Expand Down Expand Up @@ -256,8 +258,8 @@ def contains(self, mouseevent):
yt = xy[:, 1]

# Convert pick radius from points to pixels
if self.figure == None:
warning.warn('no figure set when check if mouse is on line')
if self.figure is None:
warnings.warn('no figure set when check if mouse is on line')
pixels = self.pickradius
else:
pixels = self.figure.dpi/72. * self.pickradius
Expand Down
6 changes: 6 additions & 0 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,15 @@ def get_transform(self):
return self.get_patch_transform() + artist.Artist.get_transform(self)

def get_data_transform(self):
"""
Return the :class:`~matplotlib.transforms.Transform` ... I'm not sure
"""
return artist.Artist.get_transform(self)

def get_patch_transform(self):
"""
Return the :class:`~matplotlib.transforms.Transform` ... I'm not sure
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@mdboom: Would you know what these (get_patch_transform and get_data_transform) are for? I would like to get a one liner for their purpose.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Needs resolving before merging.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

data_transform maps the data coordinates to physical coordinates.

patch_transform maps the native coordinates of the patch to physical coordinates. For example, to draw a circle with a radius of 2, the original circle goes from (-1, -1) to (1, 1) (i.e. radius == 1), and the patch transform would scale it up to 2.

"""
return transforms.IdentityTransform()

def get_antialiased(self):
Expand Down
57 changes: 51 additions & 6 deletions lib/matplotlib/tests/test_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import unittest

from nose.tools import assert_equal
import numpy.testing as np_test, assert_almost_equal
import numpy.testing as np_test
from numpy.testing import assert_almost_equal
from matplotlib.transforms import Affine2D, BlendedGenericTransform
from matplotlib.path import Path
from matplotlib.scale import LogScale
Expand Down Expand Up @@ -213,6 +214,11 @@ def setUp(self):
# self.stack1.write_graphviz(file('stack1.dot', 'w'))
# self.stack2.write_graphviz(file('stack2.dot', 'w'))
# self.stack2_subset.write_graphviz(file('stack2_subset.dot', 'w'))

def test_transform_depth(self):
assert_equal(self.stack1.depth, 4)
assert_equal(self.stack2.depth, 4)
assert_equal(self.stack2_subset.depth, 3)

def test_left_to_right_iteration(self):
stack3 = (self.ta1 + (self.tn1 + (self.ta2 + self.tn2))) + self.ta3
Expand All @@ -224,7 +230,7 @@ def test_left_to_right_iteration(self):
self.tn2 + self.ta3,
self.ta3,
]
r = [rh for lh, rh in stack3._iter_break_from_left_to_right()]
r = [rh for _, rh in stack3._iter_break_from_left_to_right()]
self.assertEqual(len(r), len(target_transforms))

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

# check that we cannot find a chain from the subset back to the superset
# (since the inverse of the Transform is not defined.)
self.assertRaises(ValueError, self.stack2_subset.__sub__, self.stack2)
self.assertRaises(ValueError, self.stack1.__sub__, self.stack2)
with self.assertRaises(ValueError):
self.stack2_subset - self.stack2

with self.assertRaises(ValueError):
self.stack1 - self.stack2

aff1 = self.ta1 + (self.ta2 + self.ta3)
aff2 = self.ta2 + self.ta3
Expand Down Expand Up @@ -312,6 +321,42 @@ def test_affine_simplification(self):
class TestTransformPlotInterface(unittest.TestCase):
def tearDown(self):
plt.close()

def test_line_extent_axes_coords(self):
# a simple line in axes coordinates
ax = plt.axes()
ax.plot([0.1, 1.2, 0.8], [0.9, 0.5, 0.8], transform=ax.transAxes)
np.testing.assert_array_equal(ax.dataLim.get_points(), np.array([[0, 0], [1, 1]]))

def test_line_extent_data_coords(self):
# a simple line in data coordinates
ax = plt.axes()
ax.plot([0.1, 1.2, 0.8], [0.9, 0.5, 0.8], transform=ax.transData)
np.testing.assert_array_equal(ax.dataLim.get_points(), np.array([[ 0.1, 0.5], [ 1.2, 0.9]]))

def test_line_extent_compound_coords1(self):
# a simple line in data coordinates in the y component, and in axes coordinates in the x
ax = plt.axes()
trans = mtrans.blended_transform_factory(ax.transAxes, ax.transData)
ax.plot([0.1, 1.2, 0.8], [35, -5, 18], transform=trans)
np.testing.assert_array_equal(ax.dataLim.get_points(), np.array([[ 0., -5.], [ 1., 35.]]))
plt.close()

def test_line_extent_predata_transform_coords(self):
# a simple line in (offset + data) coordinates
ax = plt.axes()
trans = mtrans.Affine2D().scale(10) + ax.transData
ax.plot([0.1, 1.2, 0.8], [35, -5, 18], transform=trans)
np.testing.assert_array_equal(ax.dataLim.get_points(), np.array([[1., -50.], [12., 350.]]))
plt.close()

def test_line_extent_compound_coords2(self):
# a simple line in (offset + data) coordinates in the y component, and in axes coordinates in the x
ax = plt.axes()
trans = mtrans.blended_transform_factory(ax.transAxes, mtrans.Affine2D().scale(10) + ax.transData)
ax.plot([0.1, 1.2, 0.8], [35, -5, 18], transform=trans)
np.testing.assert_array_equal(ax.dataLim.get_points(), np.array([[ 0., -50.], [ 1., 350.]]))
plt.close()

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


if __name__=='__main__':
import nose
nose.runmodule(argv=['-s','--with-doctest'], exit=False)
nose.runmodule(argv=['-s','--with-doctest'], exit=False)
Loading