用matplotlib绘制直方图 [英] Plotting histogram with matplotlib

查看:87
本文介绍了用matplotlib绘制直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在python中以直方图或条形图绘制数据.数据大小(数组大小)在0-10000之间.数据本身(数组的每个条目)取决于输入,范围在0到e + 20之间(大多数数据在同一范围内).所以我想用matplotlib做一个历史图.我想绘制一个间隔中数据的频率(以说明均值和偏差).有时它的工作方式如下: hist1 .但是有时这样的整体大小会有问题: hist2 .在此图中,我需要在0-100点处有更多条形,以此类推.谁能帮我这个?

i try to plot data in a histogram or bar in python. The data size (array size) is between 0-10000. The data itself (each entry of the array) depends on the input and has a range between 0 and e+20 (mostly the data is in th same range). So i want to do a hist plot with matplotlib. I want to plot how often a data is in some intervall (to illustrate the mean and deviation). Sometimes it works like this: hist1. But sometimes there is a problem with the intevall size like this: hist2. In this plot i need more bars at point 0-100 etc. Can anyone help me with this?

地块的制作方法如下:

from numpy.linalg import *
import matplotlib.pyplot as plt
plt.hist(numbers,bins=100)
plt.show()

推荐答案

默认情况下, hist 生成的图的x范围覆盖整个数据范围.如果您有一个局外人与其他值相比具有很高的x值,那么您将看到带有压缩"图形的图像.

By default, hist produces a plot with an x range that covers the full range of your data. If you have one outsider at very high x in comparison with the other values, then you will see this image with a 'compressed' figure.

我希望始终具有相同的视图,您可以使用 xlim 来修复限制.
另外,如果您希望分布始终居中且越好越好,则可以计算数据的均值和标准偏差,并相应地确定x范围(例如,均值+/- 5 stdev)

I you want to have always the same view you can fix the limits with xlim.
Alternatively, if you want to see your distribution always centered and as nicer as possible, you can calculate the mean and the standard deviation of your data and fix the x range accordingly (p.e. for mean +/- 5 stdev)

这篇关于用matplotlib绘制直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆