PyQtGraph doesn't provide anything like this, but it's pretty easy to write
as a QGraphicsItem class. As long as you don't need the data to update
rapidly, you can "bake" all of your line segments into a single QPicture.
This should be very quick to redraw:
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore
import numpy as np
class Segments(QtGui.QGraphicsItem):
def __init__(self, pos, color):
QtGui.QGraphicsItem.__init__(self)
self.pic = QtGui.QPicture()
painter = QtGui.QPainter()
painter.begin(self.pic)
for i in range(len(pos)-1):
painter.setPen(QtGui.QPen(QtGui.QColor(*color[i])))
p1 = QtCore.QPointF(*pos[i])
p2 = QtCore.QPointF(*pos[i+1])
painter.drawLine(p1, p2)
painter.end()
def paint(self, p, *args):
p.drawPicture(0, 0, self.pic)
def boundingRect(self):
return QtCore.QRectF(self.pic.boundingRect())
pos = np.empty((10000,2))
pos[:,0] = np.linspace(0, 10, 10000)
pos[:,1] = np.random.normal(size=(10000))
color = np.random.random(size=(9999,3)) * 255
p = pg.plot()
seg = Segments(pos, color)
p.addItem(seg)
On Tue, Aug 23, 2016 at 11:14 AM, Preston Hinkle <[email protected]> wrote:
> Hello,
>
> As the title suggests, I'm looking for a way to change the color of
> discrete segments of a PlotDataItem. My current method creates a
> PlotDataItem for every segment and plots it over the background with a
> different pen, but this is apparently very expensive when the number of
> segments accumulates to around a 1000. Instead, is it possible to draw
> segments of a single PlotDataItem with different pens? I looked through the
> documentation but couldn't find anything.
>
> Thanks!
>
> --
> 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 on the web visit https://groups.google.com/d/
> msgid/pyqtgraph/69a62e28-d917-459b-bdee-699a426e61df%40googlegroups.com
> <https://groups.google.com/d/msgid/pyqtgraph/69a62e28-d917-459b-bdee-699a426e61df%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
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 on the web visit
https://groups.google.com/d/msgid/pyqtgraph/CACZXET8o6_Ywq36rRowGNZG_g%2B0mZD6kdiQ%2BgPwnYnjYLUKU2Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.