嘿,我在 matplotlib 中有這個條形圖,我想在紅線所在的位置(不是紅條)之間添加一些空白,并調整 x-ticks,使它們位于每組條形之下。對于我現在在 jupyter 筆記本中的內容,我有以下最小示例(盡管使用的是假數據集):import numpy as npimport matplotlib.pyplot as pltset1 = [16.4, 9.5, 9.53, 9.57, 9.0]set2 = [0.8, 1.90, 1.90, 1.90, 1.90]set3 = [16.19, 2.86, 2.86, 2.86, 13.55]set4 = [12721.93, 3.81, 3.81, 3.81, 3.81]x = np.arange(5)plt.bar(x+0.00, set1, color = 'b', hatch="/", width=0.25)plt.bar(x+0.25, set2, color = 'r', hatch="\\", width=0.25)plt.bar(x+0.50, set3, color = 'g', hatch="x", width=0.25)plt.bar(x+0.75, set4, color = 'y', hatch="*", width=0.25)plt.xticks(np.arange(5, step=1), ['Set1', 'Set2', 'Set3', 'Set4', 'Set5'])plt.yscale('log',basey=10)plt.tight_layout()對于如何使用 matplotlib 實際執行此操作的想法,我完全空白,因此不勝感激。
1 回答

翻閱古今
TA貢獻1780條經驗 獲得超5個贊
x您可以通過更改第一個參數 ( ) 和 的參數width來調整條的放置位置和條的寬度plt.bar。像這樣的東西應該工作:
plt.bar(x-0.3, set1, color = 'b', hatch="/", width=0.2)
plt.bar(x-0.1, set2, color = 'r', hatch="\\", width=0.2)
plt.bar(x+0.1, set3, color = 'g', hatch="x", width=0.2)
plt.bar(x+0.3, set4, color = 'y', hatch="*", width=0.2)
添加回答
舉報
0/150
提交
取消