I am trying to use a dropdown menu to switch between linear and logarithmic scales on the X axis of my plot and I can’t understand how to specify the menu’s position.
The docs say that the position of the menu is defined in the normalized coordinates and can be anchored to a specific point (e.g. ‘left’, ‘center’). It works fine until I use the menu to switch the axis scale from log to linear or vice versa. This provokes the menu to jump horizontally. The things get even worse if I add a second menu to switch the Y axis between linear and logarithmic scales. Both menus jump horizontally and I can’t say which one is which.
Here is a minimal code to reproduce this behavior:
import plotly.graph_objects as go
x = list(range(1000))
y = [i*i for i in x]
fig = go.Figure()
fig.add_trace(go.Scatter(x=x, y=y))
# Add dropdowns
fig.update_layout(
updatemenus=[
# X scale (lin/log)
dict(
buttons=list([
dict(label="linear",
method="relayout",
args=[{'xaxis.type': "linear"}]),
dict(label="log",
method="relayout",
args=[{'xaxis.type': "log"}]),
]),
x=0.4,
xanchor="left",
y=1.2,
yanchor="top"
),
# Y scale (lin/log)
dict(
buttons=list([
dict(label="linear",
method="relayout",
args=[{'yaxis.type': "linear"}]),
dict(label="log",
method="relayout",
args=[{'yaxis.type': "log"}]),
]),
x=0.6,
xanchor="left",
y=1.2,
yanchor="top"
),
]
)
fig.show()
Update
This test was done in JupyterLab 2.1.5 environment. In Dash everything works fine. But the issue still remains since I would like to use Plotly as a graphic library in my notebooks.