✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚾️ It's finally Baseball season! Root for the home team... & Register for our Sports Analytics Webinar!

Multiple color text on scatter plot with many traces in Python

Hi!

I am creating a graph with multiple scatters (27, and each one is a different trace). When I choose nmode=‘lines+markers+text’, the scatter plot get colored itself with different color for each trace, by default, but not so the text. How can I get to use the color from the markers with the text associated? So that the text and the lines/markers share the same color?

Thanks in advance!

Try the textfont.color attribute:


trace = go.Scatter(
  x=[1,2,3],
  y=[2,1,2],
  mode='lines+markers+text',
  textfont=dict(
    color='red'
  )
)

Thanks for the answer.

Yes, I can change the color of the text with textfont.color. The problem is that I want to take the default color that plotly use for the lines/markers for the different traces and use it in textfont.color. So the lines and the tetxt are the same color. But I do not know how to get the color scheme that plotly use.

Something like this: https://plot.ly/python/text-and-annotations/#custom-text-color-and-styling

But for many traces and automatic.

Here’s the full list of default colors.

It is not what I had in mind, but it works,

Thank you!