【问题标题】:Pyqtgraph color specific regions in plotPyqtgraph在图中颜色特定区域
【发布时间】:2020-08-07 23:59:14
【问题描述】:

到目前为止,我一直在使用 matplotlib.collections,用不同的颜色标记集合相当简单。

我当前的项目要求我使用 pyqtgraph 来做同样的事情。

self.plot = pg.PlotWidget()
layout.addWidget(self.plot)

如果 bool 数组的索引 i 为真,则对应的 float 索引 i 必须着色(垂直或虚线)。

例子:

y = [50, 100, 50, 250, 150]
x = [1, 5, 87, 92, 106]
b = [False, False, True, False, True]

在绘制 87 和 106 后,应通过 x 轴上的垂直条以某种颜色或标记突出显示。有什么提示吗?

【问题讨论】:

  • 凹凸。如果您需要更多信息,请告诉我
  • 看看LinearRegionItem

标签: python python-3.x pyqt5 pyqtgraph


【解决方案1】:

我并不完全清楚您想到的可视化,但这里有几个用于标记您选择的点的选项:

  1. 使用 pg.VTickGroup 的单个实例沿 x 轴绘制刻度
  2. 使用pg.InfiniteLine 的多个实例来绘制线条和其他标记形状

例子:

import pyqtgraph as pg
import numpy as np

plt = pg.plot()

y = [50, 100, 50, 250, 150]
x = [1, 5, 87, 92, 106]
b = [False, False, True, False, True]

# draw a scatter plot with selected points in yellow
cmap = {False: (0, 0, 200), True: (255, 255, 0)}
brushes = [pg.mkBrush(cmap[x]) for x in b]
plt.plot(x, y, pen=None, symbol='o', symbolBrush=brushes)

# draw vertical ticks marking the position of selected points
tick_x = np.array(x)[b]
ticks = pg.VTickGroup(tick_x, yrange=[0, 0.1], pen={'color': 'w', 'width': 5})
plt.addItem(ticks)

# add a vertical line with marker at the bottom for each selected point
for tx in tick_x:
    l = plt.addLine(x=tx, pen=(50, 150, 50), markers=[('^', 0, 10)])

【讨论】:

  • 你的回答有点对。但不是我的想法。在查看了您的方法后,我查看了 LinearRegionItem。它非常快,可以使用边界(左限和右限)并且可以很好地完成工作,不会使查看数据变得困难,Infinite line 就是这样做的。无论如何,谢谢你的回答,我没有标记为正确答案,但我会给你赏金。
猜你喜欢
  • 1970-01-01
  • 2015-12-15
  • 2012-02-06
  • 2021-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多