亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何為繪圖上的分布范圍填充另一種顏色

如何為繪圖上的分布范圍填充另一種顏色

哈士奇WWW 2022-06-28 17:47:23
我有一個使用 a)Seaborn 和 b)Matplotlib 獲得的均勻分布的直方圖,我希望曲線下或直方圖上的特定區域用不同的顏色突出顯示。import matplotlib.pyplot as pltimport numpy as npimport seaborn as snssns.set()x = np.random.uniform(45,60, 1000)#With Seabornsns.distplot(x)plt.fill_between(50,55, color='g')#With Matplotlibplt.hist(x)plt.fill_between(50,55)但是,我收到一條錯誤消息,說我有太多的數組索引。如何在同一圖上用另一種顏色填充給定范圍的曲線或直方圖?
查看完整描述

1 回答

?
夢里花落0921

TA貢獻1772條經驗 獲得超6個贊

https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.pyplot.fill_between.html的注釋


import matplotlib.pyplot as plt

import numpy as np

import seaborn as sns


sns.set()


x = np.random.uniform(45,60, 1000)



#With Seaborn

sns.distplot(x)

# fill square defined by x, y0, y1

# need to get pdf and bins generated by sns to do fill between here


## With numpy is easier for me


# density function

y, ybin = np.histogram(x, bins=np.arange(45,61), density=True)


x_points = np.arange(50,56)

x_point_inds = np.arange(5,11)

y0 = np.zeros(6)

y1 = y[x_point_inds]


#With Matplotlib

plt.hist(x,bins=ybin,density=True, zorder=1)

plt.fill_between(x_points, y0, y1, color='g', alpha=0.5, zorder=5)


查看完整回答
反對 回復 2022-06-28
  • 1 回答
  • 0 關注
  • 130 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號