How to Output the result of an equation

Hi everyone, I am struggling to Output the value of x which would correspond to when “Turnover” equal “Costs” (see the screenshot). I was wondering if there was any equation that would solve this and How should I reorganise my @appcallback ?

Thank you very much for the help ! It is greatly appreciated :wink:

@app.callback(
    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)
    y=x*Est_ann_emissions*Price
    b= 8375 + Est_ann_emissions*0.1*x + 0.05*Est_ann_emissions*x + 0.02*Est_ann_emissions*x + 2500*x + Gap_fee + Audit_fee + Hectares_of_land*Var_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

You need to find the x value when y-b=0

I get this formula that give me that value:

 p= [-(8375 + Gap_fee + Audit_fee + Hectares_of_land*Var_costs_ha)/((Est_ann_emissions*0.1 + 0.05*Est_ann_emissions + 0.02*Est_ann_emissions + 2500)-(Est_ann_emissions*Price))]

Then I added a new trace to represent that point in the graph:

fig.add_trace(go.Scatter(x=p, y=b, name='Breaking Point'))

Then I get this results:


Then use the option you like to show the p point better and show the label as you want. :grinning:

Here is the code:

@app.callback(
    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)
    y=x*Est_ann_emissions*Price
    b= 8375 + Est_ann_emissions*0.1*x + 0.05*Est_ann_emissions*x + 0.02*Est_ann_emissions*x + 2500*x + Gap_fee + Audit_fee + Hectares_of_land*Var_costs_ha
    p= [-(8375 + Gap_fee + Audit_fee + Hectares_of_land*Var_costs_ha)/((Est_ann_emissions*0.1 + 0.05*Est_ann_emissions + 0.02*Est_ann_emissions + 2500)-(Est_ann_emissions*Price))]

    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'))
    fig.add_trace(go.Scatter(x=p, y=b, name='Breaking Point'))
    return fig
1 Like

Thank you so much mate !