Nicholas
Nicholas

Reputation: 521

Plotly.js: lock y-axis to avoid negative values

I'm using Plotly.js to plot some data that I already know cannot be negative. I need to keep the zoom and other plot "navigation" features of Plotly, yet I would disallow the user to go below the zero on the y-axis, as it does not make sense for the type of data being plotted.

Ideally, I would like to allow the zoom only in the range [0, 100], if possible.

I went through the documentation and github issues to find some ideas, so I'm not sure what I need is possible with the current release of Plotly.

Any ideas?

Thanks

Upvotes: 3

Views: 4277

Answers (2)

Hoang NK
Hoang NK

Reputation: 550

Set layout.yaxis.rangemode: 'tozero'

Upvotes: 8

Md Nasir Fardoush
Md Nasir Fardoush

Reputation: 820

You may do this to set yaxis range

var layout = {
  yaxis:{
    range:[0,100]
  }
}

Example

Upvotes: 1

Related Questions