Skip to content

[WIP] Add Axes method for drawing infinite lines. #7506

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,69 @@ def axvline(self, x=0, ymin=0, ymax=1, **kwargs):
self.autoscale_view(scalex=scalex, scaley=False)
return l

@docstring.dedent_interpd
def axline(self, slope=1, intercept=0, **kwargs):
"""
Add an infinite line across the axes.
Copy link
Member

Choose a reason for hiding this comment

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

'across an axis'?


Parameters
----------
slope : scalar, optional, default: 1
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason this and intercept are optional? I would say the user should be forced to give them.

Slope of the line.

intercept : scalar, optional, default: 0
Intercept of the line with the y-axis.

Returns
-------
:class:`~matplotlib.lines.Line2D`

Other Parameters
----------------
Valid kwargs are :class:`~matplotlib.lines.Line2D` properties,
with the exception of 'transform':

%(Line2D)s

Examples
--------
* draw a thick red line with slope 1 and y-intercept 0::

>>> axline(linewidth=4, color='r')

* draw a default line with slope 1 and y-intercept 1::

>>> axline(intercept=1)

* draw a default line with slope 5 and y-intercept 0::

>>> axline(slope=5)

See Also
--------
axhline : for strictly horizontal lines
axvline : for strictly vertical lines
Copy link
Member

Choose a reason for hiding this comment

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

Do these get automatically linked? If not would be nice to have some sphinx markup to link to relevant methods.


"""

if "transform" in kwargs:
raise ValueError("'transform' is not allowed as a kwarg; "
"axline generates its own transform.")

xtrans = mtransforms.BboxTransformTo(self.viewLim)
viewLimT = mtransforms.TransformedBbox(
self.viewLim,
mtransforms.Affine2D().rotate_deg(90).scale(-1, 1))
ytrans = (mtransforms.BboxTransformTo(viewLimT) +
mtransforms.Affine2D().scale(slope).translate(0, intercept))
trans = mtransforms.blended_transform_factory(xtrans, ytrans)

l = mlines.Line2D([0, 1], [0, 1],
transform=trans + self.transData,
**kwargs)
self.add_line(l)
return l

@docstring.dedent_interpd
def axhspan(self, ymin, ymax, xmin=0, xmax=1, **kwargs):
"""
Expand Down