plotly.js icon indicating copy to clipboard operation
plotly.js copied to clipboard

Setting only min or max values for axis and not a range.

Open shimwell opened this issue 9 years ago • 25 comments

Dear all

Many thanks for all your wonderful efforts with Plotly

I just wanted to ask if it might be possible to tweak the range function a little

currently an axis range can be set in the layout like this ...

layout = go.Layout( xaxis=dict( range=[2, 5] ),

in some cases it would be desirable to only specify a min value. Plotly can then work out the max value automatically.

Or perhaps a user would want to set a max value and have a plotly work out the min value

Either-way it would be nice (for me at least) to only specify one of the range limits and not both. However I can see why this might not be a highly required function and I'm sure there are lots of other things to do first

matplotlib offers this function ... plt.xlim(2,5) #sets a range plt.gca().set_xlim(xmin=2) # sets only the lower x value and allows computer to work out upper value plt.gca().set_ylim(ymax=50) # sets only the lower y value and allows computer to work out upper value

shimwell avatar Apr 06 '16 17:04 shimwell

Thanks for submitting the issue. You're making some valid points.

Any company out there able to sponsor this work? https://plot.ly/products/consulting-and-oem/

etpinard avatar Apr 06 '16 17:04 etpinard

I'd like to add comments to this: it is especially desirable when displaying bar charts that are meant to represent performance against a maximum, otherwise the automatic sizing creates visually misleading results.

since tickmode/tickvals when used together can be used to explicitly name tick points, perhaps adding another option to make those values fixed would be a viable feature?

Kaitensatsuma avatar Jun 10 '16 12:06 Kaitensatsuma

This feature would also be very useful when using subplots. The upper limit can be the same in axis so we could compare more easily.

cinkie avatar Oct 06 '16 19:10 cinkie

+1.

I am using extendPlots on a larger data set in which I only want to show up to the last two days (xaxis) and using extendTraces. I do not want to limit the points as extendTraces can (it doesn't know dates and it drops points completely). If range took null for one side I can envision extendTraces auto scrolling the xaxis as points are added always leaving the new points showing.

beeblebrox avatar May 15 '17 19:05 beeblebrox

I need this feature too! Sometimes I have only zero values and auto axis sets up to -1 to 1, but negative values are impossible for my data.

SaturnTeam avatar Dec 22 '17 02:12 SaturnTeam

have only zero values and auto axis sets up to -1 to 1

Have you tried setting rangemode: 'nonnegative'?

etpinard avatar Dec 22 '17 02:12 etpinard

@etpinard Thanks. It's working

SaturnTeam avatar Dec 22 '17 03:12 SaturnTeam

Has anyone found another solution to this? I am using custom controls with the update button on a chart, so the y axis scale changes every time a user clicks a different control. Plotly's default maximum value for each of them is fine but I'd like the minimum to be lower so the plot is easier to see. I tried setting axes in the layout and assigning them to each trace, but instead of the axes swapping out when a user clicks the buttons, they just all show up at once on top of one another.

layout_boxplots = go.Layout(margin=dict(t=50, b=50, l=150, r=50),    width=500,
    height=300,
    font=dict(family='Open Sans', size=14, color='#176db6'),
    showlegend=False,
    yaxis=dict(range=[-5, max(data1)]),
    yaxis2 = dict(range=[-5,max(data2)]),
    yaxis3 = dict(range=[-5,max(data3)]),
    updatemenus=updatemenus_boxplots
)

bld2104 avatar Dec 30 '17 21:12 bld2104

Is there any updated way to achieve axis starting at 0?

ravitshrivastav avatar Apr 10 '18 16:04 ravitshrivastav

@phoenixlike https://github.com/plotly/plotly.js/issues/400#issuecomment-353510549

SaturnTeam avatar Apr 11 '18 00:04 SaturnTeam

+1 on adding this. Thanks!

terrycojones avatar Jul 15 '18 23:07 terrycojones

Is there any intention to do this. I am trying to build a Dash app where user can enter a Minimum or a Maximum. It causes an issue because I have to have a default min and max or the function won't run. So far I have set defaults to be the greatest (or lowest) value in a data set plus (minus) a small value however this doesn't work for all charts (like bar charts).

oliverbrace avatar Sep 20 '18 11:09 oliverbrace

Has there been any progress on this?

MCM-Math avatar Sep 20 '18 22:09 MCM-Math

@ravitshrivastav: this is stale, but as @etpinard pointed out, rangemode: 'nonnegative' seems to do the trick.

This covers the main use case for me.

jason-curtis avatar Feb 12 '19 21:02 jason-curtis

Found the solution for setting the x or y axis's minimum value to zero. Add the following to the layout() object: yaxis = list(rangemode = 'tozero') or xaxis = list(rangemode = 'tozero')

dylanhenson avatar Jun 25 '19 19:06 dylanhenson

Thanks @dylanhenson! That's great. (I think you mean dict not list though.)

terrycojones avatar Jun 25 '19 19:06 terrycojones

Thanks @dylanhenson! That's great. (I think you mean dict not list though.)

Sorry about that, I was writing this code in R, I just realized this thread is all javascript. Hopefully rangemode = 'tozero' still works!

dylanhenson avatar Jun 25 '19 22:06 dylanhenson

I would like to set a min range for axis. In order that the axis at least shows a range of the given value, also with enabled autorange (axis is shifting foreward, if new datapointa are inserted, but has a fixed range in the beginning).

Elfangor93 avatar Jul 30 '19 08:07 Elfangor93

@ravitshrivastav: this is stale, but as @etpinard pointed out, rangemode: 'nonnegative' seems to do the trick.

This covers the main use case for me.

Is there a way to restrict the y-axis to only negative values? I tried 'rangemode':'nonpositive' and 'rangemode':'negative' but these don't seem to work. Thanks!

aanchalvazir avatar Aug 14 '20 10:08 aanchalvazir

@aanchalvazir can you provide a codepen or jsfiddle reproducing the issue you're seeing with rangemode: 'nonnegative' please in order for us to help you or to determine of this is a bug?

nicolaskruchten avatar Aug 14 '20 12:08 nicolaskruchten

Sounds like @aanchalvazir is asking for the opposite of 'nonnegative': ONLY negative values.

alexcjohnson avatar Aug 14 '20 14:08 alexcjohnson

Sounds like @aanchalvazir is asking for the opposite of 'nonnegative': ONLY negative values.

@nicolaskruchten Yes, correct. I don't mean to report a bug. I meant to ask if there is a similar approach for ONLY NEGATIVE values for y-axis in Plotly. I am unable to find a solution to that. On the contrary, a work around could be to fix the 'range' property for y-axis to something like : [-100,0] but what about cases where the lower limit (-100 in this case) is unknown?

aanchalvazir avatar Aug 14 '20 14:08 aanchalvazir

This issue has been tagged with NEEDS SPON$OR

A community PR for this feature would certainly be welcome, but our experience is deeper features like this are difficult to complete without the Plotly maintainers leading the effort.

What Sponsorship includes:

  • Completion of this feature to the Sponsor's satisfaction, in a manner coherent with the rest of the Plotly.js library and API
  • Tests for this feature
  • Long-term support (continued support of this feature in the latest version of Plotly.js)
  • Documentation at plotly.com/javascript
  • Possibility of integrating this feature with Plotly Graphing Libraries (Python, R, F#, Julia, MATLAB, etc)
  • Possibility of integrating this feature with Dash
  • Feature announcement on community.plotly.com with shout out to Sponsor (or can remain anonymous)
  • Gratification of advancing the world's most downloaded, interactive scientific graphing libraries (>50M downloads across supported languages)

Please include the link to this issue when contacting us to discuss.

jackparmer avatar Sep 10 '20 19:09 jackparmer

Same request to set axes separately from python backend

https://github.com/plotly/plotly.py/issues/3634

Proposal is to allow pass None if value should be automatically determined: range=[2, None]

ievgennaida avatar Mar 24 '22 14:03 ievgennaida

Hi is there any updates?

fzyzcjy avatar Jun 15 '22 06:06 fzyzcjy

I found a way to set one side of the y axis by adding a transparent horizontal line. For example,

fig.add_hline(y=-0.3, line_color="rgba(0,0,0,0)")

Hope this helps!

shalvichirmade avatar Dec 20 '22 15:12 shalvichirmade