-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Multiple interdependent axes #5076
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
Comments
We have support for this kind of thing via "fixed ratio axes" and "matched axes": https://plotly.com/javascript/axes/#fixedratio-axes and https://plotly.com/javascript/reference/layout/xaxis/#layout-xaxis-matches ... Do either of those meet your needs? |
I've been trying them out for a bit and I eventually found a workaround, albeit not a very pretty one. With fixedratio-axes I am able to keep a fixed ratio between a certain distance unit on the y axes, but the user can still scroll one of the axes without affecting the other, so that they become misaligned. The matches option is interesting and does keep the axes in sync. However, all the values will match exactly, whereas I am interested in one axis being an "upscaled" version of the other. This feels, intuitively, like something that shouldn't be too hard to implement by extending the "matches" property. Matches seems to override the scaleanchor and scaleratio properties, so I cannot use them together. It is possible, though, to use the matches property and formatting (https://github.com/d3/d3-format/blob/master/README.md) the text differently on different axes. By overriding the d3 locale formatter (#1464 (comment)), I was able to simply format a number as a totally different number.
Thanks a lot for the help, but I still think there is room for improvement so you don't have to rely on deceitful formatting. |
So this is pretty close, and works when box-zooming and panning: https://codepen.io/nicolaskruchten/pen/xxVOEaQ?editors=0010 I notice that grabbing and dragging the y-axis doesn't cause the y2-axis to pan, however... @alexcjohnson @archmoj is this a bug or is the box-zooming/panning a happy accident in this case? |
That system is working as intended - when you zoom or pan via the plot area, there's nothing to tell you which specific axes on that area you wanted to alter, so it alters them all. But when you zoom or pan via one of the individual axes, we only change that one. This can be quite useful if, for example, you have several traces measuring different quantities entirely but you want to see if their features match up, you can slide and scale one of them over top of the other. @kricka91 you make a good argument for why one might want |
Seems like "matches" is the wrong thing to use here... we probably just need a way to pin one axis' 0 to a level on the other. That would help with or without scaleratio in a few different circumstances actually. |
While still allowing independent scaling (via zoom interactions)? This would be interesting, but my gut reaction is much more complicated than a fixed mapping (just a more generic linear mapping than the identity of |
Yeah... someone recently brought up dual y-axes with matching 0=0 but otherwise independent scales, on the forum I think. |
It's true that for Celsius/Fahrenheit, a ratio is not enough; you would need an offset as well. Maybe an extra offset parameter would do. Or you could have a single parameter which is a formula that translates a value on one axis to another value on the other "matching" axis, which is applied to the minimum and maximum values. In the latter case, the user would be responsible for making sure that both axes are still linear if that's the desired result. Also, I currently need to insert an extra data series (without any x or y values) just to map it to the second y axis to make sure it renders. To me it would feel less ugly if I didn't need to do this, but instead just map the axis to another axis. Maybe it's difficult to change, though, and it might not be super important. One thing I like about the matches property is that the axes match in real time when you drag one of them, and not just when you release the mouse button. I would really like to retain this behavior. I noticed also that the matches property interferes somehow with autorange. When all y values are close enough to zero, the range is set to [-1, 4], which I believe is some sort of hard coded default range for plotly charts. However, if some values are outside this range, the axis range is set automatically to fit the data. (You can test it with my pasted code above; just change the y values). The problem goes away when I remove the matches property. Is this a known bug? |
re re the autorange behaviour you're describing, could you please open a separate issue with an example of this? I'd like to keep this thread focused on the initial issue if possible. "one issue per issue" keeps things more manageable :) |
This issue has been tagged with 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:
Please include the link to this issue when contacting us to discuss. |
@kricka91 Overriding the d3 locale formatter in this manner is not possible anymore with the same code with the new updates(d3.locale does not exist on plotly.js anymore). Do you know if there's an alternate way to do the same patch? |
Hi - we are trying to tidy up the stale issues and PRs in Plotly's public repositories so that we can focus on things that are still important to our community. Since this one has been sitting for a while, I'm going to close it; if it is still a concern, please add a comment letting us know what recent version of our software you've checked it with so that I can reopen it and add it to our backlog. Alternatively, if it's a request for tech support, please post in our community forum. Thank you - @gvwilson |
I would like to be able to create two y axes in a diagram, which are used for the same series, describing the y value in for example different units, such as in this example:
https://i.stack.imgur.com/ROFCo.png
As far as I can tell, there is currently no way of doing this the proper way (please correct me if I'm wrong). I don't think creating a duplicate series is an acceptable workaround as I don't want it to show up in the legend and I don't want the user to be able to hide the series and thus mess up one of the axes.
I would prefer there to be an option to link an axis to another axis rather than to a data series. The axes should remain in sync at all times as the user interacts in whatever way with the diagram.
This could theoretically be extended to more than two y axes, or to multiple x axes.
(Also, if you have any suggestions for good workarounds in the meantime, I would appreciate it.)
The text was updated successfully, but these errors were encountered: