日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python histo 改变 bins 大小_在Python中显示具有非常不均匀的bin宽度的直方图

發布時間:2023/12/2 python 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python histo 改变 bins 大小_在Python中显示具有非常不均匀的bin宽度的直方图 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這是直方圖

為了生成這個圖,我做了:

bins = np.array([0.03, 0.3, 2, 100])

plt.hist(m, bins = bins, weights=np.zeros_like(m) + 1. / m.size)

但是,正如您所注意到的,我想繪制每個數據點的相對頻率的直方圖,只有3個不同大小的區間:

bin1 = 0.03 – > 0.3

bin2 = 0.3 – > 2

bin3 = 2 – > 100

由于最后一個bin的大小相對于其他bin非常大,因此直方圖看起來很難看.如何修復直方圖?我想改變箱子的寬度,但我不想改變每個箱子的范圍.

[email?protected],這不再是直方圖,但你可以用plt.bar和np.histogram來做你想要的.然后,您只需將xticklabels設置為描述bin邊緣的字符串.例如:

import numpy as np

import matplotlib.pyplot as plt

bins = [0.03,0.3,2,100] # your bins

data = [0.04,0.07,0.1,0.2,0.2,0.8,1,1.5,4,5,7,8,43,45,54,56,99] # random data

hist, bin_edges = np.histogram(data,bins) # make the histogram

fig,ax = plt.subplots()

# Plot the histogram heights against integers on the x axis

ax.bar(range(len(hist)),hist,width=1)

# Set the ticks to the middle of the bars

ax.set_xticks([0.5+i for i,j in enumerate(hist)])

# Set the xticklabels to a string that tells us what the bin edges were

ax.set_xticklabels(['{} - {}'.format(bins[i],bins[i+1]) for i,j in enumerate(hist)])

plt.show()

編輯

如果您更新到matplotlib v1.5.0,您會發現該欄現在需要一個kwarg tick_label,這可以使這個繪圖更容易(see here):

hist, bin_edges = np.histogram(data,bins)

ax.bar(range(len(hist)),hist,width=1,align='center',tick_label=

['{} - {}'.format(bins[i],bins[i+1]) for i,j in enumerate(hist)])

總結

以上是生活随笔為你收集整理的python histo 改变 bins 大小_在Python中显示具有非常不均匀的bin宽度的直方图的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。