Matplotlib 直方图箱的选择取决于数据是否“单独”绘制。或其他一些数据:怎么会这样?
标题就有了。 :)
示例:
from numpy import random
from matplotlib import pyplot as plt
data = [1 + random.randn(1000), random.randn(1000)]
bins = 10
plt.hist(data, bins, label=['first', 'second'])
plt.hist(data[1], bins, histtype='step', label=['second again'])
plt.legend()
plt.show()
给出(选择“步骤”类型以帮助“可见性”,与默认值相同):
看到了吗?
The title has it. :)
Example:
from numpy import random
from matplotlib import pyplot as plt
data = [1 + random.randn(1000), random.randn(1000)]
bins = 10
plt.hist(data, bins, label=['first', 'second'])
plt.hist(data[1], bins, histtype='step', label=['second again'])
plt.legend()
plt.show()
gives ('step' type chosen to aid "viewability", its the same with defaults):
See?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下是 hist 当前使用(在 matplotlib git 存储库中)确定 bin 的过程:
正如您可以想象的那样,您将获得一组不同的 bin 来将 hist 与一个数据集、另一个数据集以及这两个数据集与这些条件一起使用,这并不奇怪,因为 bin_range 在所有三个实例中可能都不同。
Here is the process that hist currently uses (in the matplotlib git repo) for determining the bins:
As you can imagine, it isn't surprising that you will get a different set of bins for using hist with one data set, the other data set, and both together with these criteria because the bin_range will likely be different in all three instances.
好吧,没有人说不同的 x 轴值间隔的 bin 是相同的;)
就是这样(请参阅已接受的答案):
给出:
Ok, no one said the bins will be the same for different x-axis value intervals ;)
Here it is (see the accepted answer):
giving: