In my dash app, I have a toggle whose value determines whether the figure is a bar or a scatter plot.
The issues I have are
- the zero level moves up when the graph is refreshed from Bar to Scatter (line)
- the xlabels are expanded on the left and on the right side.
I can’t figure out why, and I do not find zhe property in the doc. I tried “layout_individual[‘autosize’]=False”, “automargin=False”, but I can’t fixe the issue.
(Note: The hor. and vert. Cyan lines are just visual guides)
Does anyone has some clue ? Ideally, I would like the axis and the xtick labels dont move at all.
problems partially fixed; I used [‘yaxis’][‘autorange’]=True and
Now both figures start at the same Y Zero-coordinates.
I still have to fix the last part of the problem : xaxis.
The behaviour I’m expecting from the xaxis when I click on the toggle is this:
But, when I plot the cumulative with a scatter, it seems that the x axis is aligned “on the left”:
To fix this, Dash would need to understand that I want the tick at the exact position where they would be if I had plotted a go.Bar. But how can I do this ?
I was thinking about an offset, but the size of a bar depends on the size of the window and on the number of bars…This offset would therefore be relative. But again : how to ??
If the bar and the scatter plots are in the same figure, Dash automatically align everything “on the center”, like here : https://plot.ly/python/graphing-multiple-chart-types/
Question is: how to align “on the center” if the bar is not in the figure?
I think the easiest way to get dash to understand that you want the ticks at the exact position where they would be if you had plotted a go.Bar would be to add a go.Bar trace to your scatter plot. If you set marker opacity to 0 it won’t appear on your scatter plot.
i.e, add an extra trace that looks like this when you switch to the scatter display:
go.Bar(x=x, y=y, showlegend=False, marker=dict(opacity=0), hoverinfo='skip')
Thanks Michaelbabyn for the workaround, it works!