我想做一些类似于http://matplotlib.org/examples/pylab_examples/hist2d_log_demo.html的内容,但我已经读到使用pylab代替python交互模式以外的代码是不好的做法所以我想这样做matplotlib.pyplot.但是,我无法弄清楚如何使用pyplot使这段代码工作.使用,pylab,给出的例子是
from matplotlib.colors import LogNorm from pylab import * #normal distribution center at x=0 and y=5 x = randn(100000) y = randn(100000)+5 hist2d(x, y, bins=40, norm=LogNorm()) colorbar() show()
我尝试了很多
import matplotlib.pyplot as plt fig = plt.figure() ax1 = fig.add_subplot(1,1,1) h1 = ax1.hist2d([1,2],[3,4])
从这里我已经尝试了plt.colorbar(h1)
plt.colorbar(ax1)
plt.colorbar(fig)
ax.colorbar()
等等的一切,我无法得到任何工作.
总的来说,即使在阅读了http://matplotlib.org/faq/usage_faq.html之后,老实说我对pylab和pyplot之间的关系还不是很清楚.例如show()
在pylab中似乎变成plt.show()
了pyplot,但由于某种原因colorbar
不成为plt.colorbar()
?
例如,