plotly / plotly.py

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

Sankey text font{color} property not changing font color. #2845

Open Dekermanjian opened 3 years ago

Dekermanjian commented 3 years ago

Hello, I am not sure if this is a bug, but the textfont property is not allowing me to change the text color of the Sankey diagram. The size and family arguments work as expected.

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, A2, B1, ...
      target = [2, 3, 3, 4, 4, 5],
      value = [8, 4, 2, 8, 4, 2]
    ),
    textfont = dict(color="red", family = "arial", size = 20)
)])

fig.update_layout(title_text="Basic Sankey Diagram", font_size=10)
fig.show()
SriBhuvaneswari commented 3 years ago

I think I can work on this.

Dekermanjian commented 3 years ago

Hi, were able to reproduce the error? Is this a bug?

EloiseRosen commented 3 years ago

Having the same problem!

xeladsn commented 3 years ago

For now, as a an alternative, you can override the text class attributes in HTML/CSS in order to style your text. For example, in my styles.css file, I have added the following :

.node-label-text-path {
  fill: rgb(250, 250, 250) !important;
  text-shadow: none
}

Works well for me !

Btw issue is duplicate of https://github.com/plotly/plotly.py/issues/2741

Nemecsek commented 2 years ago

The issue is open, but it is working in plotly 5.3.1

Cheeseycube commented 11 months ago

Just curious, is this still an issue or am I just bad at setting the font? Below is my code which sets the font properly if I use show() but not when I convert it to JSON and add it to my Flask dashboard. fig = go.Figure()

    fig.add_trace(go.Sankey(valuesuffix=value_suffix,
                node=dict(label=labels, color=label_colors),
                link=dict(
                    source=links["source"],
                    target=links["target"],
                    value=links["value"],
                    color=links["link_c"],
                ),
                textfont={'color': 'pink'}))
    # Customize plot based on earlier values
    fig.update_layout(
        title_text=title,
        font_size=font_size,
        font_family=font_family,
        font_color=font_color,
        #width=1000,
        #height=600,
        paper_bgcolor=bg_color,  # (use color name or hex code)
        title={"y": 0.9, "x": 0.5, "xanchor": "center", "yanchor": "top"}  # Centers title
    )