Skip to content

Multiple synchronized plots #298

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
TonyDIRL opened this issue Nov 13, 2015 · 8 comments
Closed

Multiple synchronized plots #298

TonyDIRL opened this issue Nov 13, 2015 · 8 comments

Comments

@TonyDIRL
Copy link

Hi,

Really great library.

Is it possible to build multiple synchronized plots with plotly?

Specifically, I'm looking to emulate the behaviour of dygraphs:
https://rstudio.github.io/dygraphs/gallery-synchronization.html

In python its possible with subplots and the shared_yaxes / shared_xaxes params.
https://plot.ly/python/subplots/

Tried the following but no success:

subplot(
    plot_ly(economics, x = date, y = uempmed),
    plot_ly(economics, x = date, y = unemploy),
    margin = 0.05
) %>% layout(yaxis=list(shared_yaxes=TRUE))

Thank you

@cpsievert
Copy link
Collaborator

Yea, this currently isn't easy to do with subplot(), but it's on my TODO list

@TonyDIRL
Copy link
Author

Thank you, that would be a really great addition.

@royr2
Copy link

royr2 commented Feb 9, 2016

I am little late to this conversation but @TonyDIRL you could do something like this:

data(managers, package = "PerformanceAnalytics")
ds <- data.frame(dts = as.Date(zoo::index(managers)), 
                 t1 = as.numeric(managers[,1]),
                 t2 = as.numeric(managers[,3]),
                 t3 = as.numeric(managers[,4]))

ds %>% 
  plot_ly(x = dts, y = t1, type = "scatter", name = "Time Series 1") %>% 
  add_trace(x = dts, y = t2, yaxis = "y2", type = "scatter", name = "Time Series 2") %>% 
  add_trace(x = dts, y = t3, yaxis = "y3", type = "scatter", name = "Time Series 3") %>% 
  layout(title = "Connected Y-Axis plot", 
         yaxis = list(title = "Series1", domain = c(0, 0.32)),
         yaxis2 = list(title = "Series2",domain = c(0.33, 0.65)),
         yaxis3 = list(title = "Series3",domain = c(0.66, 1)))

I get something like this: visit here for live version
newplot

@cpsievert I am definitely spamming layout() 😄

@TonyDIRL
Copy link
Author

TonyDIRL commented Feb 9, 2016

Awesome, thank you

@cpsievert
Copy link
Collaborator

Fixed via dd9a3fa

@lucasomigli
Copy link

Any chance of doing the same thing in Python? I am trying to decode @royr2 to have a similar thing with two different charts.

@AkthemRehab
Copy link

AkthemRehab commented Aug 1, 2022

Hello, Thanks for a great package and a helpful thread. I used the subplot command to create three synchronized plots and it worked but I noticed a bug (or maybe I am doing something wrong, please enlighten me!). Whenever I set the nrows to 3 the second and third plots from the top do not synch with the first plot (my x-axis is a date axis and I have a second x axis which is a difftime column). I did a workarond by adding a 4th row and setting its height to 0 that interestingly worked! This revealed another issue that the 0 height of a plot in subplot does not hide it, but rather shows it in a very small size. Could you please help me resolve this/these issue(s)?

@AkthemRehab
Copy link

Hello, Thanks for a great package and a helpful thread. I used the subplot command to create three synchronized plots and it worked but I noticed a bug (or maybe I am doing something wrong, please enlighten me!). Whenever I set the nrows to 3 the second and third plots from the top do not synch with the first plot (my x-axis is a date axis and I have a second x axis which is a difftime column). I did a workarond by adding a 4th row and setting its height to 0 that interestingly worked! This revealed another issue that the 0 height of a plot in subplot does not hide it, but rather shows it in a very small size. Could you please help me resolve this/these issue(s)?

On trying 5 rows the issue resurfaced again. It seems the issue is appearing for me when I try subplot with 1 column and odd number rows. Thought to share this, maybe it helps investigating.

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

No branches or pull requests

5 participants