Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotly: How to avoid drag on x axis

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.

like image 777
Raphael Fernandes Avatar asked Jun 19 '26 00:06

Raphael Fernandes


1 Answers

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)
like image 59
M Imam Pratama Avatar answered Jun 22 '26 04:06

M Imam Pratama



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!