Label font color not changing in sankey charts

Summary

I’m having a problem changing the label font color on sankey charts even after changing font_color the color won’t change. I even updated my plotly but no changes.

Steps to reproduce

Code snippet:
import streamlit as st
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_family=“Courier New”,
font_color=“blue”,
font_size=12,
title_font_family=“Times New Roman”,
title_font_color=“red”,
)
fig

If applicable, please provide the steps we should take to reproduce the error or specified behavior.

Expected behavior:
I expect the label color to change to blue as shown in line 22

Actual behavior:

The label color still remains the same no change

Debug info

  • Streamlit version: (get it with $ streamlit version)
  • Python version: (get it with $ python --version)
  • Using Conda? PipEnv? PyEnv? Pex?
  • OS version:
  • Browser version:

Requirements file

Using Conda? PipEnv? PyEnv? Pex? Share the contents of your requirements file here.
Not sure what a requirements file is? Check out this doc and add a requirements file to your app.

Links

  • Link to your GitHub repo:
  • Link to your deployed app:

Additional information

If needed, add any other context about the problem here.

Hey @Dennis,

This is what I see when I run your code:

Are you trying to change the color of “Basic Sankey Diagram” to something else? Or is it a different element that you’re trying to change the color of?

Also just a note that I did have to fix the type of double quotes in your code when I copy-pasted it (this could be related to the issue you’re seeing, or maybe not). This is what the code looks like after I updated the quotes:

import streamlit as st
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_family="Courier New",
font_color="blue",
font_size=12,
title_font_family="Times New Roman",
title_font_color="red",
)
fig

I am trying to change the colors of labels A1, A2, B1 etc… as you can see they are not visible enough.

Hi @Dennis , this does seem like a bug. However, just to confirm, do you have an example of a sankey chart changing the text color without streamlit?

I tried looking for examples briefly but couldn’t find much that I could see where the text color in sankey changed.

Thanks @willhuang i ran the code in jupyter notebook it worked. Seems the bug is on streamlit or something

@Dennis , can you paste the code so I can reproduce and also paste an image of what it should look like? That would help a lot as sometimes it’s hard to get time to work on these bugs as things are starting to ramp up on the open source team and more responsibilities are coming in!

@willhuang sorry for the late reply got held up with work and some stuff. Below is the jupyter code and the pic

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_family=“Times New Roman”,
font_color=‘red’,
font_size=12,
title_font_family=“Times New Roman”,
title_font_color=“red”,

)
#fig.update_traces(legendgrouptitle_font_color=‘blue’, selector=dict(type=‘sankey’))
fig.show()

I’m dealing with the same problem. Did anyone find a solution?

Use jupyter notebook and the problem will be solved. I posted the solution with a code and an image.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.