Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!
I am trying to create a clustered bar chart. My python code currently seems to have create a stacked bar chart. I'm relatively new to Python so I'm not too sure why this is. Please see below an image of what I am seeing:
Below is an example of the clustered bar chart that I am trying to create using a Python script:
I am including a link to the file below:
https://www.mediafire.com/file/7txd1k0knab2b81/Example_Table.pbix/file
In addition you can find the code I used below:
Thanks in advance.
Solved! Go to Solution.
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.
Vote for your favorite vizzies from the Power BI World Championship submissions!
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 57 | |
| 53 | |
| 40 | |
| 17 | |
| 16 |
| User | Count |
|---|---|
| 116 | |
| 105 | |
| 41 | |
| 34 | |
| 25 |