我有一组数据:
x = np.array([1,1,1,2,2,2,3,3,3,4])
y = np.array([1,2,3,1,2,3,1,2,3,1])
z = np.array([0.1,0.9,0.75,0.8,1,1.2,0.6,0.3,0.1,9])
在这里您可以看到x值重复,y值也一样。现在,我想作一个图,以便对于x和y的每个坐标,我都有一个对应的值z。
我尝试了以下方法:
fig, ax = plt.subplots()
x = np.unique(x) # Get only non-repeated values from x
y = np.unique(y)
X, Y = np.meshgrid(x, y)
a = df.index.values # This data is just and examplification, I actually have the data as dataframe
if a.all() % 2 != 0: # Just a condition to make a 2d array
cu = np.reshape(z,(-1,2))
dose = (cu / 1e-9) * 3.38E-3
scat = ax.scatter(X, Y, c=dose, s=abs(x[0] - x[1]), marker='s', cmap='jet')
ax.margins(0.05)
plt.show()
这段代码给我一个错误,说数组的形状不匹配。如何解决?
这是我要绘制的图像的一个例子。