When x axis range enabled, data don't show up

Hi,

In dash python app, I use figure/graph with date on x axis and value on y axis. I also use go.Bar-s to show data on primary y axis and go.Line-s to show data on secondary axis.

I wanted to disable autoscaling so I have added fig.update_xaxes(range=[start_date, end_date]) which works well. But I have noticed if there is data only for one tick(date), I’m not able to see it for primary y axis(secondary has values). If I click on enable autoscale on top of the graph, data becomes visible.

Is this some plotly bug?

Thanks,
Ognjen

HI @ogi welcome to the forums.

Could you please provide a code example?

Here it is:

@app.callback(
    Output('user_oem_by_period', 'figure'),
    [Input('picker-range', 'start_date'),
     Input('picker-range', 'end_date'),
     Input('duration_dropdown', 'value'),
     Input('project', 'value')],
    [State('url', 'search')]
)
def user_oem_by_period(start_date, end_date, duration_value, oem_product, search):
    duration_value = "week" if not duration_value else duration_value
    logging.info(
        f"start_date : {start_date}, end_date: {end_date} ,duration_dropdown : {duration_value},search : {search} ")
    query_params = dict(urllib.parse.parse_qsl(search[1:]))
    oem_value = oem_dict[query_params.get('oem', 'default')]
    entities = fetch_usage_data(start_date, end_date, oem_value, duration_value, oem_product)

    # Set Drivers trace as default because it always should display first.
    traces_by_grouping = {"Drivers": Trace("Drivers")}
    [traces_by_grouping.setdefault(entity["usage_grouping"], Trace(entity["usage_grouping"])).add_entity(entity) for entity in entities]

    fig = make_subplots(specs=[[{"secondary_y": True}]])
    fig.update_yaxes(range=[0, 100], secondary_y=True)
    fig.update_xaxes(range=[start_date, end_date])
    fig.update_layout(plot_bgcolor="white")

    if duration_value == 'day':
        fig.update_xaxes(tickformat='%d\n%B', tickmode='auto')
    elif duration_value == 'week':
        fig.update_xaxes(dtick='604800000.0', tick0='2022-12-26',
                         tickformat='%d\n%b')  # 604800000.0 is time in miliseconds
    elif duration_value == 'month':
        fig.update_xaxes(dtick='M1', tickformat='%b %Y')

    [fig.add_trace(trace.as_bar()) for trace in list(traces_by_grouping.values())]
    [fig.add_trace(trace.as_line(), secondary_y=True) for trace in get_percentage_traces(traces_by_grouping)]
    return fig

    def as_bar(self):
        return go.Bar(x=self.x, y=self.y, name=self.name)

    def as_line(self):
        return go.Line(x=self.x, y=self.y, name=self.name)

I have discovered it is about go.Bar. It could be it is up to the fact there is on enough place to the left to show all 5 bars I expect.

Hi @AIMPED, was code snippet helpful? Let me know if additional clarification are needed. Thanks!