繁体   English   中英

我需要有关如何在以下条形图中将绿色条移动到蓝色条左侧的指导

[英]I need guidance on how to move the green bar to the left side of the blue bar in the following bar chart

绿色条与蓝色条重叠。 有人可以告诉我如何将绿色条移动到蓝色条的右侧吗? 我希望三个条对齐。

import matplotlib.pyplot as plt
import numpy as np
N = 9
labels = ['L', 'S', 'S', 'M', 'W', 'W', 'S', 'R', 'C']    
M = [0.76, 44.91, 28.43, 10.59, 4.06, 6.53, 0.80, 0.02, 0.25]
PO_means = [2.60, 58.19, 17.20, 7.81, 3.10, 7.45, 1.38, 0.06, 1.39]
K_means = [1.3, 48.2, 26, 9.8, 3.2, 7.1, 0.03, 1, 0.7]

x = np.arange(len(labels))  # the label locations
width = 0.30  # the width of the bars

fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, M, width, label='M S and K', color=('#b02a2a'))
rects2 = ax.bar(x + width/2, PO_means, width, label='PO S and K', color=('#055cad'))
rects3 = ax.bar(x + width/2, K_means, width, label='M K', color=('#0b7d53'))

# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('% of workday', fontsize=32)
#ax.set_title('Scores by group and gender')
ax.set_xticks(x) 
ax.set_xticklabels(labels, fontsize=32) 
ax.legend(loc='upper right', frameon=False, fontsize=25, markerscale=2)

ax.bar_label(rects1, size = 32, padding=3) 
ax.bar_label(rects2, size = 32,  padding=3) 
ax.bar_label(rects3, size = 32,  padding=3)
plt.xticks(ha='center') 
for tick in ax.xaxis.get_major_ticks():
    tick.label.set_fontsize(32) 
for tick in ax.yaxis.get_major_ticks():
    tick.label.set_fontsize(32) 
plt.ylim(0, 100) 
plt.gca().spines['right'].set_color('none')
plt.gca().spines['top'].set_color('none')
#fig.tight_layout()

plt.show()

更改这些行:

rects1 = ax.bar(x - width/2, M, width, label='M S and K', color=('#b02a2a'))
rects2 = ax.bar(x + width/2, PO_means, width, label='PO S and K', color=('#055cad'))
rects3 = ax.bar(x + width/2, K_means, width, label='M K', color=('#0b7d53'))

至:

rects1 = ax.bar(x - width, M, width, label='M S and K', color=('#b02a2a'))
rects2 = ax.bar(x, PO_means, width, label='PO S and K', color=('#055cad'))
rects3 = ax.bar(x + width, K_means, width, label='M K', color=('#0b7d53'))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM