[英]Change x-axis on FacetGrid or set limits on fill_between
[英]Matplotlib Ribbon Plot (fill_between) with a Categorical X-Axis
我有一個組的均值和標准差,我想創建一個均值並由標准差遮蓋的功能區圖 ,但是我有x_axis分類列。 似乎有一個自動排序功能,可以將所有內容丟棄。
## Environmental Variables
x_axis = ['Hematite','Illmenite','Goethite','Magnetite','Quartz','Gibbsite','1:1 Clay','Maghemite','Carbonate Minerals','Plagioclase','2:1 Clays','Dolomite','Pyroxene','Calcite','Olivine','Glass']
negative_means = numpy.array([0.14335727,0.05707763,-0.25710322,-0.31085691,0.45552229,0.0092398,0.33358032,-0.31261271,-0.34325373,-0.32826959,-0.22494553,-0.13867505,0.42883104,0.52948655, -0.13867505,0.52948655])
negative_std = numpy.array([0.9218578779912541,1.0417523903222377,0.7225001946958459,0.6634664468936872,1.8400873597252276,1.2279905419059247,1.3735242455660657,0.721879847038041,0.5543207488394122,0.7817647212788771,0.0,0.0,2.088217480513372,2.2160413265187904,0.0,2.216041326518791])
fig, ax = plt.subplots(1)
ax.plot(negative_means, lw=2, label='mean population 1', color='blue')
plt.fill_between(x_axis, negative_means+negative_std, negative_means-negative_std, facecolor='blue', alpha=0.5)
## Set x labels
ax.set_xticklabels(x_axis)
x_max = int(max(plt.xticks()[0]))
# manually set xtick labels
plt.xticks(range(0, x_max + 1), x_axis, rotation=45)
如何將我的繪圖表述為類似於x_axis的以下問題。
當我將x_axis添加到ax.plot函數中時,將生成結果圖:
我只是使用為您的分類變量指定x值的range
來更改fill_between
的x
參數。 休息一切都很好在您的代碼。 根據此處的官方文檔, x
值應為定義曲線的cx x
。 您可以堅持在繪圖時不要通過x_axis
,這並不是按照x_axis
的上述評論的最佳方法
plt.fill_between(range(len(x_axis)), negative_means+negative_std, negative_means-negative_std, facecolor='blue', alpha=0.3)
plt.tight_layout()
產量
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.