-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Axes.axline: implement support transform argument (for points but not slope) #18647
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
Changes from 1 commit
cf835e3
527aa46
45e5bc7
bd8e82b
da040d0
02b8c59
9292f18
f6ee501
0b0ea4e
6d93918
d7c31c3
da0b344
fe54cd1
db44748
690177e
257be32
425ee2d
4649b9f
82e63a9
21deaf4
a2584af
a5aa349
91e851e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1440,6 +1440,34 @@ def draw(self, renderer): | |
super().draw(renderer) | ||
|
||
|
||
class _AxLineTransAxes(_AxLine): | ||
""" | ||
A helper class that implements `~.Axes.axline_transaxes`, by recomputing | ||
the artist transform at draw time. | ||
""" | ||
|
||
def __init__(self, xy1, slope, **kwargs): | ||
super().__init__([0, 1], [0, 1], **kwargs) | ||
self._slope = slope | ||
self._xy1 = xy1 | ||
|
||
def get_transform(self): | ||
ax = self.axes | ||
(vxlo, vylo), (vxhi, vyhi) = ax.transScale.transform(ax.viewLim) | ||
x, y = (ax.transAxes + ax.transData.inverted()).transform(self._xy1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't it be simpler to calculate the slope into axes coordinates and simply draw the line in axes co-ordinates? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. I tried to stay close to the implementation of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, but it won't really get much simpler because we still need to somehow convert to data coordinates to calculate at which edges of the viewport (top/bottom or left/right) the ends of the line would be. That will of course depend on the current x/y limits. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wont the line clip if you just make it go from x_axes = -1 to 2? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, right, it does. I implemented a simpler solution in da040d0, however it breaks the tests even though the plots visually seem to look the same. The difference seems to be very small, not sure why this is happening 😕 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could probably safely up the tolerance if this is just roundoff from passing the positions through the transform stack...
|
||
|
||
# find intersections with view limits in either direction, | ||
# and draw between the middle two points. | ||
_, start, stop, _ = sorted([ | ||
(vxlo, y + (vxlo - x) * self._slope), | ||
(vxhi, y + (vxhi - x) * self._slope), | ||
(x + (vylo - y) / self._slope, vylo), | ||
(x + (vyhi - y) / self._slope, vyhi), | ||
]) | ||
return (BboxTransformTo(Bbox([start, stop])) | ||
+ ax.transLimits + ax.transAxes) | ||
|
||
|
||
class VertexSelector: | ||
""" | ||
Manage the callbacks to maintain a list of selected vertices for | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4072,6 +4072,19 @@ def test_axline(fig_test, fig_ref): | |
ax.axvline(-0.5, color='C5') | ||
|
||
|
||
@check_figures_equal() | ||
def test_axline_transform(fig_test, fig_ref): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be useful to add a test where you call the method, and then subsequently resize the figure (simulating a manual resize) and show this still yields the expected line. Also that its robust to panning and zooming. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. I added some an additional test in 45e5bc7 which uses |
||
ax = fig_test.subplots() | ||
ax.set(xlim=(-1, 1), ylim=(-1, 1)) | ||
ax.axline_transaxes((0, 0), slope=1) | ||
ax.axline_transaxes((1, 0.5), slope=1, color='C1') | ||
|
||
ax = fig_ref.subplots() | ||
ax.set(xlim=(-1, 1), ylim=(-1, 1)) | ||
ax.plot([-1, 1], [-1, 1]) | ||
ax.plot([0, 1], [-1, 0], color='C1') | ||
|
||
|
||
def test_axline_args(): | ||
"""Exactly one of *xy2* and *slope* must be specified.""" | ||
fig, ax = plt.subplots() | ||
|
Uh oh!
There was an error while loading. Please reload this page.