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!Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now
I have a bar chart and I am trying to create a custom colour rule whereby if the colour is greater than 0 then green if it is less than 0 then red. I have never used conditional formatting in Python but this is the base code that I have:
import pandas as pd
from matplotlib import pyplot as plt
plt.bar(dataset.Type,dataset.Amount, color="green")
plt.show()
Thanks in advance.
Solved! Go to Solution.
Hi @HamidBee
You can try this
import pandas as pd
from matplotlib import pyplot as plt
colors = []
for amount in dataset.Amount:
if amount >= 0:
colors.append("green")
else:
colors.append("red")
plt.bar(dataset.Type,dataset.Amount, color=colors)
plt.show()
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
Hi @HamidBee
You can try this
import pandas as pd
from matplotlib import pyplot as plt
colors = []
for amount in dataset.Amount:
if amount >= 0:
colors.append("green")
else:
colors.append("red")
plt.bar(dataset.Type,dataset.Amount, color=colors)
plt.show()
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
Much appreciated.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
Check out the February 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 65 | |
| 59 | |
| 45 | |
| 19 | |
| 15 |
| User | Count |
|---|---|
| 109 | |
| 108 | |
| 39 | |
| 30 | |
| 26 |