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()
.
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.
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()
?
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 . You may want to try:
ax.imshow(h[0], interpolation='nearest')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.