0

So I have a pretty basic Sankey plot pretty similar to the one in the documentation:

import plotly.graph_objects as go

fig = go.Figure(data=[go.Sankey(
    node = dict(
      pad = 15,
      thickness = 20,
      line = dict(color = "black", width = 0.5),
      label = ["A1", "A2", "B1", "B2", "C1", "C2"],
      color = "blue"
    ),
    link = dict(
      source = [0, 1, 0, 2, 3, 3], # indices correspond to labels, eg A1, A2, A1, B1, ...
      target = [2, 3, 3, 4, 4, 5],
      value = [8, 4, 2, 8, 4, 2]
  ))])

fig.update_layout(title_text="Basic Sankey Diagram", font_size=10)
fig.show()

enter image description here

What I want to do is to change the color of the label (A1,A2..). How do I go about it?

JohanC
  • 71,591
  • 8
  • 33
  • 66
Tarique
  • 463
  • 3
  • 16

1 Answers1

1

Read the reference documentation carefully :)

fig.update_traces(textfont_color=<VALUE>, selector=dict(type='sankey'))

this should set the fontcolor of your node labels

Konstantin Z
  • 146
  • 7
  • Thanks for this and the documentation link. Also is there any way to change or remove the background color that we have just around the text in the plot above? – Tarique Mar 11 '22 at 05:13
  • @Tarique , I haven't found any mention of this "text shade" in the documentation (but don't trust me, check yourself). My guess is that it depends on the _**plot_bgcolor**_ as in [this example](https://plotly.com/python/sankey-diagram/#style-sankey-diagram) – Konstantin Z Mar 11 '22 at 08:39
  • I tried that but it does not work. I couldn't find anything that did in the documentation – Tarique Mar 11 '22 at 09:38
  • Theoretically, you can get around that with annotations, since you control every aspect of its text and box. But manually substituting every label with corresponding annotation is a hell of a work. Try asking the same question on [plotly forum](https://community.plotly.com) – Konstantin Z Mar 12 '22 at 10:29
  • 1
    Also, I was wrong: it is **paper_bgcolor** that controls the shade of node labels – Konstantin Z Mar 12 '22 at 11:06