✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🧬 Learn how to build RNA-Seq data apps with Python & Dash. Register for the May 20 Webinar!

Bar Chart is not displayed correctly

My bar chart in Dash does not display the whole bar but just a line marking the highest value of the corresponding bar.

Find below my code.
The dataframe is normally set up, meaning for each X there is one Y

def update_graph3(start_date, end_date, selection):
    global df_r

    lag = 6

    df_r_filter = RC.create_timeseries(df_r, start_date, end_date, selection)

    df_weights = RC.create_portfolio_weights(df_r_filter, lag)
    mcr_rp, _, _ = RC.create_mcr(df_r_filter, 1_000_000, df_weights)

    fig = go.Figure(go.Box(
        x = mcr_rp.index,
        y = mcr_rp['Daily_d_VaR']))

    return fig

Thanks for your help!

Not sure, but I would recommend you try to print out your x,y values to see what you’re trying to plot. So, just above the “fig=go.Figure” insert the line:

print (mcr_rp.index)
print (mcr_rp['Daily_d_VaR'])

What do those printouts give you?

Hey Adam,

Index(['HML', 'Momentum', 'CashFlow', 'SMB'], dtype='object')
HML          4999.633589
Momentum     7023.823656
CashFlow    13636.922602
SMB          1901.631649
Name: Daily_d_VaR, dtype: float64

The Output looks right to me or am I wrong?

Thanks for your help! Much appreciated!

Hi @Maeaex1
Ok, I see. You’re missing data.

Your asking Plotly to create a Boxplot (not bar chart) with 4 categories on the x_axis, but only 4 values on the y_axis. That’s why you’re getting only one lines on the graph. You have only 1 numerical value for each category. The y_axis usually has many values for each category, allowing the plot to generate a bar chart or boxplot.
See this for examples: Plotly-boxplots

Thanks for the hint.

    trace = go.Bar(x = mcr.index,y = mcr['Daily_d_VaR'] )

    return {'data': [trace]}

Did the job! Wish you a nice sunday!