pyqtgraph的等级曲线:isocurve
问题描述:
有没有人知道使用isocurve从pyqtgraph获得这个(level curves from matplotlib)的方法? 这里是我的代码...pyqtgraph的等级曲线:isocurve
谢谢!
from pyqtgraph.Qt import QtGui,QtCore
import numpy as np
import pyqtgraph as pg
import sys
#data creation
app=QtGui.QApplication([])
x = np.linspace(0,6.28,30)
y = x[:]
xx,yy = np.meshgrid(x,y)
z = np.sin(xx)+np.cos(yy)
win = pg.GraphicsWindow()
win.setWindowTitle('esempio isocurve')
vb = win.addViewBox()
img = pg.ImageItem(z)
vb.addItem(img) #visualizes img in viewbox vb
vb.setAspectLocked() #set img proportions (?)
c = pg.IsocurveItem(data=z,level=2,pen='r')
c.setParentItem(img) #set img as parent of the isocurve item c (?)
c.setZValue(10) #I DO NOT KNOW THE MEANING OF THIS, JUST COPIED FROM THE EXAMPLE isocurve.py
vb.addItem(c)
win.show()
sys.exit(app.exec_())
答
[解决]我不得不为了编辑“functions.py”在行〜1500摆脱错误的
"TypeError: Cannot cast ufunc add output from dtype('int32') to dtype('uint8') with casting rule 'same_kind'".
文件“functions.py”位于 C:\ Users \ my_name \ AppData \ Local \ Programs \ Python \ Python35 \ Lib \ site-packages \ pyqtgraph(Windows搜索引擎没有找到它,因为它位于隐藏文件夹内!)。下面是修改通过this Google Group建议:
index += (fields[i,j] * 2**vertIndex)
成为
index += (fields[i,j] * 2**vertIndex).astype(np.ubyte).
在我的代码,我必须设置
level=0
,而不是
level=2
,为2大于马z的最大值。换句话说,我试图画一条1500米山峰的2000米水平曲线。永远记得提供一个合适的水平! Here's the correct output(-.-')