简体   繁体   English

使用 matplotlib.pyplot.imshow() 绘制二维直方图时出现“TypeError:dtype 对象的图像数据无法转换为浮点数”

[英]"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:我在没有插值的情况下生成的图如下所示:

在此处输入图片说明

The hist2d matplotlib function returns the binned 2D array, but also the xedges and yedges , check the docs here . hist2d matplotlib 函数返回分箱的二维数组,还有xedgesyedges ,请在此处查看文档 You may want to try:您可能想尝试:

ax.imshow(h[0], interpolation='nearest')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 plt.imshow()给出TypeError:无法使用PyTorch将dtype对象的图像数据转换为float - plt.imshow() gives TypeError: Image data of dtype object cannot be converted to float using PyTorch 在Matplotlib.pyplot.imshow()中从OpenCV显示2D数组 - Display 2D array from OpenCV in Matplotlib.pyplot.imshow() 使用matplotlib.pyplot.imshow()时如何确定颜色? - How to determine the colours when using matplotlib.pyplot.imshow()? TypeError: dtype object 的图像数据无法转换为浮点数修复 - TypeError: Image data of dtype object cannot be converted to float Fix 类型错误:dtype 对象的图像数据无法转换为浮点数 - TypeError: Image data of dtype object cannot be converted to float 图像在matplotlib.pyplot.imshow上看起来不错,但是当在QT GUi上使用Qimage显示时,图像却严重扭曲 - Image looks good on matplotlib.pyplot.imshow , but is horribly distorted when shown on QT GUi using Qimage TypeError:dtype对象的图像数据无法转换为float。 当显示来自神经网络的图像时 - TypeError: Image data of dtype object cannot be converted to float . When showing image from neural net TypeError: dtype object 的图像数据无法转换为浮点数 - 使用 Seaborn 的 HeatMap Plot 问题 - TypeError: Image data of dtype object cannot be converted to float - Issue with HeatMap Plot using Seaborn 如何在matplotlib.pyplot.imshow中标记单元格(绘制单元格边框) - How to mark cells in matplotlib.pyplot.imshow (drawing cell borders) matplotlib.pyplot.imshow 中的神器 - Artifact in matplotlib.pyplot.imshow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM