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!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
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.
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 143 | |
| 123 | |
| 102 | |
| 79 | |
| 54 |