[英]"TypeError: Image data of dtype object cannot be converted to float" when drawing 2d histogram using matplotlib.pyplot.imshow()
I made 2D histogram using matplotlib.pyplotlt.hist2d()
but since the function hist2d()
does not inherently have the option for interpolation(smoothing), I tried to use matplotlib.pyplot.imshow()
.我使用
matplotlib.pyplotlt.hist2d()
制作了 2D 直方图,但由于函数hist2d()
本身没有插值(平滑)选项,我尝试使用matplotlib.pyplot.imshow()
。
The following is part of my code:以下是我的代码的一部分:
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)
This gives the error saying TypeError: Image data of dtype object cannot be converted to float.
这给出了错误信息
TypeError: Image data of dtype object cannot be converted to float.
I searched for the similar examples but I could not figure out what is the problem with my code.我搜索了类似的例子,但我无法弄清楚我的代码有什么问题。
How can I solve this problem?我怎么解决这个问题? OR is there alternative way for 2d histogram interpolation without using
imshow()
?或者是否有不使用
imshow()
2d 直方图插值的替代方法?
The plot I generated without interpolation is like the following:我在没有插值的情况下生成的图如下所示:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.