Tengo una figura plotly express:
fig = px.line(data, x="DateTime", y="Gold", title="Gold Prices")
Quiero cambiar algunos detalles, así
fig.update_layout( line_color="#0000ff", # ValueError: Invalid property specified for object of type plotly.graph_objs.Layout: 'line' line=dict( color='rgb(204, 204, 204)', width=5 ), # Bad property path: line )Pero ambos intentos (probar soluciones que investigué aquí) fallaron, con los errores que se dan en los comentarios.
También probé fig = px.line(data, x="DateTime", y="Gold", title="Gold Prices", template="ggplot2", color_discrete_map={"Gold": "green"}) para Sin resultado.
¿Cómo hago que esto funcione por favor?
plotly.express
Si desea utilizar plotly.express, agregue la siguiente configuración.
import plotly.express as px df = px.data.stocks() fig = px.line(df, x='date', y="GOOG", title='Ticker:GOOG') fig['data'][0]['line']['color']='rgb(204, 204, 204)' fig['data'][0]['line']['width']=5 fig.show()plotly.graph_objects
Si está utilizando plotly.graph_objects, puede configurarlo en go.Scatter().
import plotly.express as px import plotly.graph_objects as go df = px.data.stocks() fig = go.Figure(data=go.Scatter(x=df['date'], y=df['GOOG'], mode='lines', line_color='rgb(204, 204, 204)', line_width=5)) fig.update_layout(title='Ticker:GOOG') fig.show()Intente usar .update_traces() con plotly.express en lugar de .update_layout() :
fig.update_traces(line_color='#0000ff', line_width=5)Intenta usar la función "set_color" así:
fig.set_color('b')o
fig.set_color('g') donde g y b también pueden ser r para el esquema de color RGB. luego fig.show()