✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

How to plot different lines using formulas on the same graph with Dash

Hi everyone,

Here is the problem I am struggling with, I want to plot different lines on the same graph using Dash, the line chart won’t show when I start the app. I have tried with px.line as well as go.figure.

I am just beginning with coding so it might be easy to fix. Here is the code and what appears on the Dash App.

Thank you very much for your help ! :wink:

Output(component_id=‘our_graph’, component_property=‘figure’),
[Input(component_id=‘Estimated_Annual_tCO2’, component_property=‘Value’),
Input(component_id=‘Price_tCO2’, component_property=‘value’),
Input(component_id=‘Hectares_of_land’, component_property=‘Value’),
Input(component_id=‘Variables_costs_ha’, component_property=‘Value’),
Input(component_id=‘Gap_analysis_fee’, component_property=‘Value’),
Input(component_id=‘Audit_fee’, component_property=‘Value’)]

def update_graph(Est_ann_emissions, Price, Hectares_of_land, Var_costs_ha, Gap_fee, Audit_fee):
x=np.arange(0, 11)
b= 8375 + Est_ann_emissions0.1x + 0.05Est_ann_emissionsx + 0.02Est_ann_emissionsx + 2500x + Gap_fee + Audit_fee + Hectares_of_landVar_costs_ha
fig = go.Figure()
fig.add_trace(go.Scatter(x=x, y=y, name=‘Turnover’)),
fig.add_trace(go.Scatter(x=x, y=b, name=‘Costs’))

return fig

Hi @marquymarc and welcome to the community!

The component_property is case sensitive, which means it can only accept value as lower cased or else it’ll throw an error.

Another tip for you - While pasting your code in the post, click on the code icon of the editor and paste the code within the highlighted section of the code markdown. Check this post for futher reference.

Man, thank you so much ! You just saved me tons of time

1 Like