-1

我想在同一轴上使用条形图和折线图,条形图具有基于不同变量的颜色代码,并将其作为返回值传递给 Dash。 .graph.有人可以告诉我我哪里出错了吗?

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.graph_objs as go
import pandas as pd
import time
import plotly.express as px
import numpy as np
pd.set_option(‘display.width’, 400)
pd.set_option(‘display.max_columns’, 50)

df1 = pd.read_csv(r"E:\OI\test_mar_2020.csv")
df1[‘Date’] = pd.to_datetime(df1[‘Date’])
df1[‘Monthly_Exp_End’] = pd.to_datetime(df1[‘Monthly_Exp_End’])
df1[‘Monthly_Exp_Start’] = pd.to_datetime(df1[‘Monthly_Exp_Start’])
df1[‘Monthly_exp_end_ind’] = np.where(df1[‘Monthly_Exp_End’]==df1[‘Date’] , True, False)
df = df1[df1[‘Year’].isin([2020])]

external_stylesheets = [‘https://codepen.io/chriddyp/pen/bWLwgP.css’]

app = dash.Dash(name, external_stylesheets=external_stylesheets)

party_data = 
for client in df[‘Client_Type’].unique():
party_data.append({‘label’: client, ‘value’: client})


app.layout = html.Div([
html.Div([
dcc.Dropdown(id=‘client-picker’,options=party_data,value= ‘Test1’ )]),
dcc.Graph(id=‘graph’)
])

@app.callback(Output(‘graph’, ‘figure’), [Input(‘client-picker’, ‘value’)])
def update_figure(client_picker_name):
df_new = df[df.Client_Type == client_picker_name]

我想在下面的trace1中添加一个颜色参数lile plotly.express— fig = px.scatter(df, x=“sepal_width”, #y=“sepal_length”, color=“species”)

 trace1 = go.Bar(x=df_new.Date, y=df_new.colA)
 trace2 = go.Bar(x=df_new.Date, y=df_new.colB)
 trace3 = go.Scatter(x=df_new.Date, y=df_new.colC, mode=‘lines+markers’, yaxis=‘y2’)

return {
‘data’ : [trace1,trace2,trace3]
}

if name == ‘main’:
app.run_server(debug=True,port = 8080)
4

1 回答 1

0

你需要在color里面传递参数marker

trace1 = go.Bar(x=df_new.Date, y=df_new.colA, marker=dict(color='green'))
于 2020-04-04T16:33:47.133 回答