Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
shimwell opened this issue Apr 6, 2016 · 26 comments · Fixed by #6547
Closed

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

shimwell opened this issue Apr 6, 2016 · 26 comments · Fixed by #6547
Labels
feature something new

Comments

@shimwell
Copy link

shimwell commented Apr 6, 2016

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
@etpinard
Copy link
Contributor

etpinard commented Apr 6, 2016

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/

@Kaitensatsuma
Copy link

Kaitensatsuma commented Jun 10, 2016

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?

@cinkie
Copy link

cinkie commented Oct 6, 2016

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.

@etpinard etpinard added the feature something new label Nov 28, 2016
@beeblebrox
Copy link

+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.

@SaturnTeam
Copy link

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.

@etpinard
Copy link
Contributor

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

Have you tried setting rangemode: 'nonnegative'?

@SaturnTeam
Copy link

@etpinard Thanks. It's working

@bld2104
Copy link

bld2104 commented Dec 30, 2017

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
)

@ravitshrivastav
Copy link

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

@SaturnTeam
Copy link

@phoenixlike #400 (comment)

@terrycojones
Copy link

+1 on adding this. Thanks!

@oliverbrace
Copy link

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).

@MCM-Math
Copy link

Has there been any progress on this?

@jason-curtis
Copy link

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

This covers the main use case for me.

@dylanhenson
Copy link

dylanhenson commented Jun 25, 2019

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')

@terrycojones
Copy link

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

@dylanhenson
Copy link

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!

@Elfangor93
Copy link

Elfangor93 commented Jul 30, 2019

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).

@aanchalvazir
Copy link

@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!

@nicolaskruchten
Copy link
Contributor

@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?

@alexcjohnson
Copy link
Collaborator

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

@aanchalvazir
Copy link

aanchalvazir commented Aug 14, 2020

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?

@jackparmer
Copy link
Contributor

jackparmer commented Sep 10, 2020

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.

@ievgennaida
Copy link

ievgennaida commented Mar 24, 2022

Same request to set axes separately from python backend

plotly/plotly.py#3634

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

@fzyzcjy
Copy link

fzyzcjy commented Jun 15, 2022

Hi is there any updates?

@shalvichirmade
Copy link

shalvichirmade commented Dec 20, 2022

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature something new
Projects
None yet
Development

Successfully merging a pull request may close this issue.