Open stan-servaenergy opened 1 year ago
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui, QtWidgets
app = pg.mkQApp()
plt = pg.PlotWidget()
plt.show()
plt.plot([1, 2, 3], [10, 2, 1])
text = QtWidgets.QGraphicsSimpleTextItem("testing")
text.setBrush(QtCore.Qt.GlobalColor.white)
y = text.boundingRect().height() + 2
text.setTransform(QtGui.QTransform(1,0,0,-1,0,y))
plt.addItem(text)
# debug placement
rectitem = QtWidgets.QGraphicsRectItem(text.boundingRect())
rectitem.setPen(pg.mkPen('r', style=QtCore.Qt.PenStyle.DashLine))
plt.addItem(rectitem)
app.exec()
Thank you, pijyoi for your example on how to workaround the issue. Following it, I was able to resolve LabelItem
placement for my use case.
Is there anything I can help with to create a permanent fix for everyone?
Could you provide a scenario where plotting scaled text would be useful? The following snippet surely isn't one of them.
import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui, QtWidgets
import numpy as np
app = pg.mkQApp()
plt = pg.PlotWidget()
plt.show()
x = np.linspace(-10,10,201)
y = np.sinc(x)
plt.plot(x, y)
text = QtWidgets.QGraphicsSimpleTextItem("testing")
text.setBrush(QtCore.Qt.GlobalColor.white)
y = text.boundingRect().height() + 2
text.setTransform(QtGui.QTransform(1,0,0,-1,0,y))
pt = QtCore.QPointF(0, 1)
text.setPos(pt)
plt.addItem(text)
# debug placement
rect = text.boundingRect()
rect.moveTo(pt)
rectitem = QtWidgets.QGraphicsRectItem(rect)
rectitem.setPen(pg.mkPen('r', style=QtCore.Qt.PenStyle.DashLine))
plt.addItem(rectitem)
app.exec()
In my use case, I have a DAG (Directed acyclic graph) and use ScatterPlotItem
with large size
argument to display nodes as oversized "bubbles". I'm using LabelItem
to place node description labels inside those "bubbles". The width of edges between nodes also conveys information.
I'm using pxMode
set to False
, so that "bubbles" shrink/expand as you zoom in/out. Without it I was getting "casino chip" effect of nodes staying same screen size and obscuring edges or even whole plot when zoomed out.
Perhaps this is bit abusing the components and I should have developed custom GraphItem
, but initially this looked like a easy way to go.
Short description
LabelItem
inverted in Y-axis, possibly also at wrong coordinates.Code to reproduce
Expected behavior
Label has normal orientation.
Real behavior
Label is upside down and probably at wrong coordinates too.
Tested environment(s)
0.13.3
PySide6 6.5.2 Qt 6.5.2
(also tried 6.2.2)3.11.4
(also tried 3.10)1.24.4
Linux fes 6.3.3-060303-generic #202305171336 SMP PREEMPT_DYNAMIC Wed May 17 13:45:19 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
pip
Additional context
I need to use
LabelItem
instead ofTextItem
, because for my use case I need my plot labels to scale with plot (e.g. zoom in/out).