In the code below, I can't get the label to hug the y axis when the graph
is resized. If the graph is resized smaller/larger, the label is truncated
or additional space appears between the y axis and the label. Any ideas on
how to position the label adjacent to the y axis for all graph sizes?
import sys
import numpy as np
from PyQt5.QtWidgets import QApplication
import pyqtgraph as pg
app = QApplication(sys.argv)
win = pg.GraphicsLayoutWidget(show=True, title="y = exp(x) with Movable
Line")
plot = win.addPlot(title="y = exp(x) with Movable Line")
x = np.linspace(-2, 2, 1000)
y = np.exp(x)
plot.plot(x, y, pen='b')
# Create a movable infinite horizontal line with a label that updates
based on y-position
h_line = pg.InfiniteLine(pos=1.0, angle=0, movable=True)
plot.addItem(h_line)
h_line.label = pg.InfLineLabel(h_line, text=f"y = {h_line.value():.2f}",
position=0.05, color='r', fill=(255, 255, 255, 255))
def update_label():
h_line.label.setText(f"y = {h_line.value():.2f}")
h_line.sigPositionChanged.connect(update_label)
sys.exit(app.exec_())
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/pyqtgraph/d23b4182-e1b1-4fb3-b5f3-1e6d0d8c4902n%40googlegroups.com.