用百分比绘制条形图

时间:2019-05-03 04:27:24

标签: python matplotlib

在绘制带有百分比的条形图时,我需要一些帮助。我需要这样的情节:

bar of overall males    bar of overall females
bar of hired males      bar of hired females
x axis: Males, Females 

我正在尝试这样的事情:

y = [139437,689]  # [Overall Males, Hired Males]
z = [82693,545]   # [Overall Females, Hired Females]
x = [Males, Females]  # on x-axis

ax = plt.subplot()
ax.bar(x-0.1, y, width=0.1, color='b')
ax.bar(x, z, width=0.1, color='g')

plt.show()

请在这里提供代码帮助我。

1 个答案:

答案 0 :(得分:0)

您想要实现的目标可能是一个起点

import matplotlib.pyplot as plt

y = [139437, 82639]  # [Overall Males/Females]
z = [689, 545]   # [Hired Males/Females]
x = ['Males', 'Females']  # on x-axis

ax = plt.subplot()
ax.bar(x, y, width=0.5, color='b', label='all')
ax.bar(x, z, width=0.5, color='g', label='hired')
plt.legend()

plt.show()

但是请注意,总值雇用值之间的差异是如此之大,以至于根据您的目的,这种可视化可能不是最好的。