我使用matploitlib箱線,以創建像下面這樣的數字:的Python:在箱線圖一箱的設置背景
使用此代碼:
# Create a figure instance
fig = plt.figure(1, figsize=(4, 4))
# Create an axes instance
ax = fig.add_subplot(111)
ax.set_ylim([0, 1.2])
# Create the boxplot
bp = ax.boxplot(data_to_plot,widths=(0.5, 0.5))
plt.setp(bp['boxes'], linewidth=1)
# Save the figure
plt.xticks([1, 2], ['A', 'B'],fontsize=16)
plt.yticks(fontsize=16)
#fig.savefig('fig1.png', bbox_inches='tight')
plt.show()
我試圖要着手爲每個盒子設置背景,以便它們具有不同的顏色。
感謝
這裏看一個例子:http://matplotlib.org/examples /pylab_examples/boxplot_demo2.html – roadrunner66