如何从以下名为think_or_feel的Pandas数据帧创建等高线图:
think feel
cNEU cOPN
y n 27 20
n n 40 23
y y 43 25
n y 97 63我尝试过以下几种方法:
X=think_or_feel.columns
Y=think_or_feel.index
Z=think_or_feel.values
x,y=np.meshgrid(X, Y)
plt.contourf(x,y,Z)我得到以下错误:unhashable type: 'numpy.ndarray'
我真的很感激在这方面的任何帮助。
发布于 2020-09-29 11:07:57
我猜原因是您的索引/列不是数字,而plt.contourf需要数字。让我们试一试:
X=np.arange(think_or_feel.shape[1])
Y=np.arange(think_or_feel.shape[0])
Z=think_or_feel.values
plt.contourf(x,y,Z)
plt.xticks(X, think_or_feel.columns)
plt.yticks(Y, think_or_feel.index)输出:

https://stackoverflow.com/questions/64111684
复制相似问题