我對 sns.histplot() 有問題。據我了解,bins 引數應該表明圖中應該有多少個垃圾箱。這是一些用于可視化奇怪(至少對我而言)行為的代碼。
d = {'col1': [1, 2, 3, 4, 5, 6, 7, 8, 9 , 10 , 11 , 12, 13, 14, 15], 'col2': [1, 1, 1, 1, 1, 1, 2, 2, 2 , 2 , 2, 2, 2, 2, 2]}
df = pd.DataFrame(data=d)
sns.histplot(data=df, x='col1', multiple='dodge', hue='col2', binwidth=2, bins=8)

我的原始代碼中有幾乎相同的問題
hist = sns.histplot(data=Data, x=y_data, multiple='dodge', ax=axes[0], hue=i[2][1], binwidth=2, bins=10)
正如您所看到的,只有一個 bin 的資料具有最小值和 std,但沒有分成我宣告的 bin 數量。誰能解釋一下為什么這不將資料拆分為提供的垃圾箱數量?如何更改代碼以確保容器數量恒定?
uj5u.com熱心網友回復:
我認為問題是 binwidth 引數。也許只是嘗試洗掉該引數,或將其設定為較小的值(0.2 或 0.1)
uj5u.com熱心網友回復:
從docs,關于binwidth引數:
每個 bin 的寬度,覆寫
bins但可以與binrange.
所以,你不能同時指定bins,并binwidth在同一時間。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/349183.html
標籤:Python 蟒蛇-3.x 熊猫 matplotlib 海生
