plotly express plots have faded colors
Asked Answered
M

1

7

I am having issues with plotly express in Jupyter notebook. The colors in the plot are faded and do not match the colors in the legend, which they are supposed to look like. Does anyone have any suggestions? Happy to provide more info, but I am not sure what would be useful - I am still new to Python.

enter image description here

fig = px.bar(funded_apps_mask_kewt, x='Grant Expended CY Quarter', y='Grant 
Expended Amount', color='AMI Status',title='Long-Form Input')
fig.update_xaxes(categoryorder='category ascending')
fig.show()


AMI Statu | Grant Exp | Grant Exp Q | Grant Exp Q | Grant Exp Year | Grant Exp QY
0 Very Low (50%)    20086.72 Q4 2020    Q4              2020           2020 Q4
1 Urgent Need (120%)20086.7  Q4 2020    Q4              2020           2020 Q4
2 Urgent Need (120%)20086.72 Q4 2020    Q4              2020           2020 Q4
3 Very Low (50%)    20086.72 Q4 2020    Q4              2020           2020 Q4
4 Low (80%)         20086.72 Q4 2020    Q4              2020           2020 Q4
5 Low (80%)         20086.72 Q4 2020    Q4              2020           2020 Q4
6 Low (80%)         20086.72 Q4 2020    Q4              2020           2020 Q4
82Low (80%)         35602.75 Q1 2021    Q1              2021           2021 Q1

This is what my data looks like. I changed the column names so they could fit, but the columns I used are 'AMI Status', 'Grant Exp', and 'Grant Exp QY'. It has ~7K rows.

Moua answered 13/2, 2021 at 3:32 Comment(5)
That's quite peculiar. This isn't the behavior I would expect unless the opacity has somehow been set. Can you include a sample of your DataFrame so we can try to reproduce your issue?Paramount
@DerekO I edited the post with a sample of the data. Thanks!Moua
Update - when I use a sample of the data with 10 rows, the color doesn't fade - this only appears to happen when using a lot of rows.Moua
Update - I was able to fix by using groupby() to make a new dataframe with the sums of 'Grant Exp' by 'Grant Exp QY' and 'AMI Status'. This removed the white lines from the thousands of blocks of data that made the colors appear lighter, and my new dataframe was only about 30 rows. When there was so many datapoints the white border lines created this problem and made the colors appear to fade.Moua
Ah that makes sense now! You should post what you did as an answer and then accept your own answer so that people with a similar problem can solve it too :)Paramount
Q
9

This is because of the bar outline, which can be removed by setting the marker.line.width attribute to 0:

fig.update_traces(dict(marker_line_width=0))
Quillen answered 3/4, 2021 at 19:33 Comment(3)
I am having the same issue, but why it suddenly happens? I have been using Plotly for a long while, but I haven't seen it before. Do I have to do this in all Jupyter notebook in the future?Pieter
Adding this before fig.show() worked for me, thanks for the fixScanlon
One more thing, the changes you made through update_traces() method will not be reflected if you save it as image via fig.write_image(), but it will be reflected if you do fig.write_html().Logjam

© 2022 - 2024 — McMap. All rights reserved.