我使用pyqtgraph进行数据采集,并且必须在图形视图中表示一些阈值。例如代表高电压限制等。
我使用了pyqtgraph中的InfiniteLine
类,但是现在,我必须考虑在获取过程中阈值可能发生的一些变化。它看起来像是两条无限线之间的一个台阶(请参阅附件中的示例)。在
为此,我不得不画一条半无限长的线。你知道一个简单的方法吗?在
我考虑过使用一些受viewBox最小值和最大值限制的plotCurveItem:
thresholdValue = 60V # just an example
range = self.viewBox.viewRange()
xRange = range[0] # we only want ViewBox horizontal limits
minView = xRange[0]
maxView = xRange[1]
myPlotCurveItem = pyqtgraph.PlotCurveItem([minView, maxView],[thresholdValue, thresholdValue])
如果阈值发生变化:
^{pr2}$plotCurveItem的x数据将变为:
[minView, changingTime] #with changinTime : the moment we change the threshold
我们会添加一个新的曲线图:
myNewPlotCurveItem = pyqtgraph.plotCurveItem([changingTime, maxView],[newThresholdValue, newThresholdValue])
这个解决方案看起来不错还是有什么问题?在
谢谢你非常完整的回答! 你的代码运行得很好。 为了设置多个阈值转换,我对你的类InfiniteLineWithBreak做了一些修改。 我只修改了init和paint方法:
此外,我还添加了一个方法,将一个新的阈值转换点附加到HersHoldAndItsDate的耦合列表中:
^{pr2}$下面是它的一个示例: example of multiple thresholds
你觉得代码没问题吧? 谢谢你
您的方法看起来不错,主要是
pyqtgraph.InfiniteLine
正在做的事情。我检查了the source of InfiniteLine并提取了那些绝对必要的部分,添加了变化点和两个层次的信息,然后画了三条线(左边界到左水平的变化点,在右水平上改变点到右边界,两者的连接)。在以下是完整代码:
它看起来像:
可以添加的是鼠标悬停和更改值的反应(更改点和级别),甚至旋转90度。
InfiniteLine
就是一个很好的例子。在相关问题 更多 >
编程相关推荐