Colors 用于plotly小提琴绘图的离散颜色序列

Colors 用于plotly小提琴绘图的离散颜色序列,colors,plotly,sequence,violin-plot,Colors,Plotly,Sequence,Violin Plot,如何将颜色序列颜色离散\u序列=[“绿色”、“蓝色”、“黄色”、“洋红”]应用于下图中的“星期日”、“星期六”、“星期四”、“星期五”,即星期日应为绿色、星期六蓝色等 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 = g

如何将颜色序列
颜色离散\u序列=[“绿色”、“蓝色”、“黄色”、“洋红”]
应用于下图中的“星期日”、“星期六”、“星期四”、“星期五”,即星期日应为绿色、星期六蓝色等

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()
给予


Plotly express似乎是正确的方式;看来我把它框错了

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()
给予