Skip to content

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

Closed
@scottshambaugh

Description

@scottshambaugh

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions