-
Notifications
You must be signed in to change notification settings - Fork 632
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
Update y-axis range when x-axis rangeslider is used #912
Comments
I'm not sure I agree this is a better default behavior -- especially considering that optimal aspect ratios depends on the context, and it's much easier to zoom in on the y-axis rather than zoom out. That isn't to say we couldn't make it easier to opt-in to this behavior, but it would be better asked/implemented as a feature request in plotly.js -- https://github.com/plotly/plotly.js FWIW, you can already take advantage of that Javascript solution from R via |
Firstly, thank you for the tip about using However, it still probably worth at least visually demonstrating here with two charts how the default behaviour is falling short... particularly when it comes to charting financial stocks. The first chart is the APPLE stock without Y-scaling implemented. Its very evident the trace becomes quasi-flat. With the Y-scaling implemented using the onRender method.... it maintains a much superior aspect ratio in the 2nd chart. |
I'm trying to solve this same issue with plotly range buttons on a Shiny app. Could you share your code you used to fix it in R? I read through the Javascript solution you posted, but unfortunately for me, my javascript skills are rusty. Since it is a Shiny web app, is it possible for me to put javascript in the head of the document to fix the y-axis scaling? Here's an example of what I need to fix:
|
@ldsmike88 just FYI, a support plan might be worthwhile in your case -- https://support.plot.ly/plans |
you have to use the onRender() method and add it to the plotly object.
But to be honest... until y-scaling is built into plotly its not a desirable solution. For this reason I'm now using highcharter which has built in scaling. You can solve your y-scaling problems doing this.
|
Highcharter looks very good, but unfortunately, you have to pay for commercial use. I ended up using Dygraphs. Not as graphically pleasing as Highcharter or Plotly, but it got the job done. Here's my code:
Thanks for all of your help! |
#1040 enables you to modify plotly graphs in shiny using the plotly.js API. I've made a demo which addresses this issue. Try it out with: devtools::install_github("ropensci/plotly#1040")
library(plotly)
demo("proxy-relayout", package = "plotly") |
It crashed for me as soon as I tried to change the slider range. |
Interesting, mind reporting the output you see in the R console? Also, the output of |
I'm using R version 3.2.3 (2015-12-10). The error is:
|
Ah, good to know, thanks! Should be fixed now, try reinstalling. |
I got it working with my example. Your demo seemed to be too much for my system to handle. It kept crashing RStudio.
It works fine whenever you click "30 days" or use the range slider, but it doesn't relayout when you click "All." Not a big deal. I can work with this. Thanks for all your help! Do you anticipate plotlyProxy being included in an official release soon? |
Interesting...does it work in a modern browser (e.g., firefox/chrome)?
Yep, same for me, feel free to improve on it ;)
Hopefully next week or sooner |
@cpsievert Awesome work! |
Is this going to be added as standard any time soon? I'm starting a new project using financial charts and was considering using plotly dash, but this functionality doesn't seem available in python. i'm looking for exactly this |
Did you find out how to do it in Python? |
Please post an issue here if you want it python https://github.com/plotly/plotly.py |
cpsievert, thanks for all the awesome work you're doing on plotly for R users. I have a simple question: Is there a way to update a plotly plot when the dataframe it is plotting is changed, as an equivalent of this code from above: lets say I have a data frame with x, y (and z possibly) data I plot in 2D or 3D with n groups to color / group by, and then the user either loads a new file that should be shown in the same plotly plot, or rbinds a new piece of data, adding an extra group to the dataframe. |
I struggled with getting this to work so I developed a code example to share. Example provides automatic updates to the yaxis range when and x range slider is updated. Y axis is set to show only price range of bars that are in the chart with a two tick padding. This worked well for me and I can potentially add any number of trace overlays that I want on top of the chart. Plus, I can run it locally without having to use plotly services. See gitub repo here: https://github.com/gersteing/DashCandlestickCharting/blob/master/README.md For whom ever wants to try it out. Runs locally using Flask. Enjoy |
I have used the python library to create html file with candlesticks (challege was to integrate it with talib for pattern recognition), where the js file was seperated from the data. In the original js plotly file, why does one need to add a plotly_relayout event, when the corresponding function group to be possibly edited is at For example, I have DAX OHLC data with extreme values (11436,11220).
How is this related to the function of group 729
Any ideas? I am not a js person, but shouldn't one adjust the autorange part of these functions instead of calling another eventhandler? Or am I wrong? |
This should 100% be the default behavior of the range slider. |
This is what currently happens with Plotly when using the range slider. If a short interval x-axis range from the slider is selected, the displayed trace(s) could become quasi flat:
This occurs because the y-axis range is not updating when using the range slider. IMHO this seems to defeat the point of having a range slider.
Others have already realised this and have implemented a solution in the JS version of Plotly.
Javascript solution
To achieve updating y axis range, it listens to plotly_relayout event, use it's eventdata (xaxis.range) to filter the data, and redraw the plot with filtered data.
The only remaining issue is that the range slider y axis changes and therefore does not display the traces in full.
Is this feature something that could be easily implemented in the R version?
The text was updated successfully, but these errors were encountered: