PyQtGraph updateItems 源码
时间: 2023-10-12 17:32:47 浏览: 49
在PyQtGraph中,PlotCurveItem对象的updateItems()方法用于更新绘图元素。下面是它的源代码实现:
```python
def updateItems(self):
if self.xData is None:
return
if self.opts['stepMode'] is False:
if self.opts['fillLevel'] is not None:
# Draw as filled curve
x = np.concatenate((self.xData, self.xData[::-1]))
y = np.concatenate((self.yData, self.opts['fillLevel'] * np.ones(len(self.xData))[::-1]))
self.fill.setData(x=x, y=y, **self.opts)
self.fill.show()
else:
self.fill.hide()
self.curve.setData(x=self.xData, y=self.yData, **self.opts)
else:
# Draw as stepped line
px = np.empty((self.xData.size * 2,))
py = np.empty((self.yData.size * 2,))
px[0::2] = self.xData
px[1::2] = self.xData[:-1]
py[0::2] = self.yData
py[1::2] = self.yData[1:]
stepStyle = self.opts['stepMode']
if stepStyle == 'center':
px -= (self.xData[1] - self.xData[0]) / 2.
elif stepStyle == 'right':
px[0::2] += (self.xData[1] - self.xData[0])
px[1::2] += (self.xData[1] - self.xData[0])
self.curve.setData(x=px, y=py, **self.opts)
self.fill.hide()
self.curve.setVisible(self.opts['connect'])
self.curve.setShadowPen(self.opts['shadowPen'])
```
updateItems()方法首先检查PlotCurveItem对象是否有任何数据。如果没有数据,则返回。否则,它根据PlotCurveItem的opts字典中的选项来确定如何绘制曲线。
如果stepMode选项为False,则绘制平滑曲线。如果fillLevel选项不为None,则绘制填充曲线。否则,隐藏填充曲线。
如果stepMode选项为True,则绘制阶梯线。在这种情况下,需要将x和y数据拆分为两个数组,并将它们重组为阶梯形式的数组。然后,根据stepMode选项的值对数组进行微调。最后,使用setData()方法将x和y数据设置为阶梯形式的数组。
最后,updateItems()方法设置曲线和填充的可见性,并设置曲线的阴影线。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)