我使用制作了2D直方图,matplotlib.pyplotlt.hist2d()
但是由于该函数hist2d()
固有地没有插值(平滑)选项,因此我尝试使用matplotlib.pyplot.imshow()
。
以下是我的代码的一部分:
fig, ax=plt.subplots(figsize=(8,6))
ax.set_title('Joint Distribution of NND for San Ramon Earthquakes')
h=ax.hist2d(T,D,30,density=True)
ax.imshow(h, interpolation='nearest')
plt.colorbar(h[3],ax=ax)
这给出了错误,表明TypeError: Image data of dtype object cannot be converted to float.
我搜索了类似的示例,但是我无法弄清楚我的代码有什么问题。
我怎么解决这个问题?或者是否有不使用二维直方图插值的替代方法imshow()
?
我没有插值生成的图如下所示:
该hist2d
matplotlib函数返回分级二维数组,但也xedges
并yedges
,检查这里的文档。您可能要尝试:
ax.imshow(h[0], interpolation='nearest')
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句