2

I need to prevent the dragging on the x axis (the one that moves the axis and its curves), but without loosing the zoom feature (selecting an area on the graph). I've found exactly this question on Plotly forum, but there aren't answers.

Copying the text for convenience:

I want to keep this functionality:

enter image description here

But I want to disable this:

enter image description here

My attempt was:

fig.update_layout({
            'xaxis': {'fixedrange': True},
            'xaxis2': {'fixedrange': True},
)}

This snippet blocks the x axis drag as well as the zoom. Selecting fixedrange for only one of the axis blocks the dragging but the zoom goes bugged (zooming only the curves of one of the axes). Is there any way with plotly arguments or maybe by CSS (by adding a css file on assets folder), by preventing the click on the axis based on the id and maybe the children.

2 Answers2

1

According to the js and python config docs, the complete list of configuration options are available at the plotly.js source code on GitHub: https://github.com/plotly/plotly.js/blob/master/src/plot_api/plot_config.js

Search for showAxisDragHandles:

showAxisDragHandles: {
    valType: 'boolean',
    dflt: true,
    description: [
        'Set to *false* to omit cartesian axis pan/zoom drag handles.'
    ].join(' ')
},

Usage :

config = dict(showAxisDragHandles=False)

# plotly.py
fig.show(config=config)

# plotly-dash
graph = dcc.Graph(figure=fig, config=config)
EricLavault
  • 12,130
  • 3
  • 23
  • 45
M Imam Pratama
  • 998
  • 11
  • 26
0

You can use fig.update_layout(dragmode=False) which will disable the drag without affecting the ability to zoom. See here for a further explanation.

Derek O
  • 16,770
  • 4
  • 24
  • 43
  • Thanks for your answer. I tried your solution but the zoom by clicking on the graph area did not work. When using the zoom by the icon in the top right, I can zoom in both directions but, when reseting the axes, the bug is back. – Raphael Fernandes May 05 '23 at 16:25
  • @RaphaelFernandes let me see if there is any workaround for this – Derek O May 06 '23 at 20:33