-1

How can I apply the color sequence color_discrete_sequence=["green", "blue", "yellow", "magenta"] to the days “Sunday”, “Saturday”, “Thursday”, “Friday” in the plot below, i.e. Sunday should be green, Saturday blue etc?

import plotly.graph_objects as go
import pandas as pd

df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/violin_data.csv")

fig = go.Figure()

fig.add_trace(go.Violin(x=df['day'], y=df['total_bill'],                        
                        line_color='rgba(255,0,0,0.5)'
                       )
             )


fig.update_traces(box_visible=False, meanline_visible=True,
                  points='all', pointpos=-0, jitter=0.5,
                  marker_line_color='rgba(0,0,0,0.5)',
                  marker_line_width=1,
                  
                  showlegend=False)

fig.update_layout(template='simple_white')

fig.show()

gives

Violin plot

hans
  • 323
  • 1
  • 14

1 Answers1

1

Plotly express seems the right way to go; looks like I framed it not correctly.

import plotly.express as px
import pandas as pd

df = px.data.tips()

fig = px.violin(df, x='day', y="total_bill", color='day',
                color_discrete_sequence=["green", "blue", "yellow", "magenta"])

fig.update_traces(box_visible=False, meanline_visible=True,
                  points='all', pointpos=-0, jitter=0.5,
                  marker_line_color='rgba(0,0,0,0.5)',
                  marker_line_width=1,                  
                  showlegend=False)

fig.update_layout(template='simple_white')

fig.show()

gives

Violin plot with custom color sequence

hans
  • 323
  • 1
  • 14