plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
16.11k stars 2.54k forks source link

non-dynamic textfont color when using continuous color scales #3196

Closed jarvas24 closed 3 years ago

jarvas24 commented 3 years ago

Current Behavior (plotly version 4.14.3)

When using the text property in a bar trace with a continuous color scale, the textfont.color is static; all bars use the same text color, which results in difficult to read text for some bars (far right bar in screenshot).

import plotly.express as px
x = list(range(1, 10))
px.bar(x=x, y=x, color=x, text=[str(i) for i in x])

image

Expected/Desired Behavior

The text font color should be dynamic (dark text on light colored bars, light text on dark bars), just like the hover text. Bar traces with discrete colorscales already have this behavior:

import plotly.express as px
x = list(range(1, 10))
px.bar(x=x, y=x, color=[str(i) for i in x], text=[str(i) for i in x], color_discrete_sequence=px.colors.sequential.Plasma)

image

ArkaprabhaChakraborty commented 3 years ago

Is anyone working on this? If not then I want to work on this.

nicolaskruchten commented 3 years ago

No one is working on it as far as I know, and we'd love the help! The right place to solve this is in the underlying Javascript library Plotly.js. We've actually got code that does this for pie charts and treemaps I believe, so it may be quite straightforward to port it to bars :)

@archmoj or @alexcjohnson can advise.

nicolaskruchten commented 3 years ago

Looks like this is getting fixed in https://github.com/plotly/plotly.js/pull/5666 actually :)