Skip to content
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

Request: allow plotting a labelLine outside the data range #176

Open
scottshambaugh opened this issue Apr 10, 2024 · 1 comment
Open

Request: allow plotting a labelLine outside the data range #176

scottshambaugh opened this issue Apr 10, 2024 · 1 comment

Comments

@scottshambaugh
Copy link

scottshambaugh commented Apr 10, 2024

To use the first example as a starting point, say I want to put all the labels for the lines to the right of the lines at x=1.05. Right now if I try to do the below, I get the error: ValueError: x label location is outside data range!

But I think it would be useful functionality to be able to place a label at an arbitrary x value for the closest data edge's y value.

An alternative way to get this behavior would be to allow passing in an xoffset for the labels.

import numpy as np
from matplotlib import pyplot as plt
from scipy.stats import chi2, loglaplace
from labellines import labelLine

X = np.linspace(0, 1, 500)
A = [1, 2, 5, 10, 20]
funcs = [np.arctan, np.sin, loglaplace(4).pdf, chi2(5).pdf]

fig, ax = plt.subplots()

for a in A:
    ax.plot(X, np.arctan(a * X), label=str(a))
for i in range(len(A)):
    labelLine(ax.get_lines()[i], 1.05, zorder=2.5)

image

@cphyc
Copy link
Owner

cphyc commented Apr 10, 2024

The difficulty with the general case is that you'd have to interpolate somehow the data outside of its range - and there are no unique choices for the interpolation: linear? same value? cubic? Your suggestion of having an x-offset seems easier.

Unfortunately, I don't have the bandwidth to implement any new feature but I would be happy to review any PR if you want to have a go!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants