如何在matplotlib.pyplot中使用带有hist2d的colorbar?

 我就唔分_753 发布于 2023-01-06 18:03

我想做一些类似于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()

例如,

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有