Forum Discussion
Stacked bar chart to clustered bar chart using a Python script
- Anonymous4 years ago
Hi HamidBee ,
To include multiple X values on the same chart, we can reduce the width of the bars and then place the indices one bar’s width further from the y axis.
Please try:
import numpy as np from matplotlib import pyplot as plt N = 12 ind = np.arange(N) width = 0.3 plt.xlabel('Month') plt.ylabel('Value') plt.title('Month vs Value') plt.bar(ind,dataset['Total A 2021'],width,color='black', label='2021') plt.bar(ind + width,dataset['Total A 2020'], width,color='grey',label='2020') plt.xticks(ind + width / 2, ('Jan', 'Feb', 'Mar', 'Apr', 'May','Jun','Jul','Aug','Sep','Oct','Nov','Dec')) plt.legend() plt.show()Refer to:
https://benalexkeen.com/bar-charts-in-matplotlib/
Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi HamidBee ,
To include multiple X values on the same chart, we can reduce the width of the bars and then place the indices one bar’s width further from the y axis.
Please try:
import numpy as np
from matplotlib import pyplot as plt
N = 12
ind = np.arange(N)
width = 0.3
plt.xlabel('Month')
plt.ylabel('Value')
plt.title('Month vs Value')
plt.bar(ind,dataset['Total A 2021'],width,color='black', label='2021')
plt.bar(ind + width,dataset['Total A 2020'], width,color='grey',label='2020')
plt.xticks(ind + width / 2, ('Jan', 'Feb', 'Mar', 'Apr', 'May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'))
plt.legend()
plt.show()
Refer to:
https://benalexkeen.com/bar-charts-in-matplotlib/
Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.