How to align ticks for multiple y axis so all grid squares are equal size
This is best explained by the screenshot:

As you can see the grid squares differ in size, I'd like these to remain constant. Instead I'd like the y2 axis ticks to scale to match the y axis values, i.e. the y axis would step up like 10,20,30 but the y2 axis would step up with respect to those values i.e. 12, 24, 36 etc. Is this possible with plotly?
You can make this happen manually (set yaxis2.dtick and if necessary yaxis2.tick0) but that will only last until the viewer changes the y/y2 ranges independently (or even the two ranges together assuming you're using automatic ticks on yaxis). If you're in an environment where you can attach event handlers you could listen to plotly_relayout events and update these values whenever either range changes. There's no way to automatically do it.
I suppose it would be possible to add a setting like yaxis2.tickmode = 'match overlay' (assuming you also have yaxis2.overlaying = 'y') that would match pixel positions of ticks/grids between the two. It would in general not look that great though - unless you've set it up specifically, you're likely to end up with ticks at 12.33333 or the like.
Another solution you may be interested in is turning the gridlines off and using showspikes and spikemode: across
Any update on this issue? Is there any workaround or hacky solution?
No updates, and the only workarounds I'm aware of are those I mentioned above. This would be a great issue for a community PR.
@ankuradhey If this is a deal breaker then you may want to try out Flot see this example http://www.flotcharts.org/flot/examples/axes-multiple/index.html This would be a great addition to plotyjs (currently this is the only factor blocking our team switching to it as our primary graphing library).
I've come across the same issue, so I'm having a crack to see if I can write something that will generate compatible ranges for both axes. Can't promise anything but if it bears fruit I'll both stick it on GitHub and have a look at making a PR out of it.
@alexcjohnson Thanks for the hint about dtick and tick0. This helped for my use-case but some "automated" way of doing it would be even more awesome 😸
Just a quick idea: Isn't all that it takes to have the same amount of ticks and interdistance on both axes? Wouldn't something like synchronizeTickCount and making sure that both sides have the same amount of ticks and interdistance then suffice? You'd just need to mathematically derive the necessary dtick to achieve that.
Just a quick idea: Isn't all that it takes to have the same amount of ticks and interdistance on both axes?
That's enough for dtick but tick0 also needs to be set appropriately. But it occurs to me in the most general case even that wouldn't do it, because the ticks you're matching needn't be linearly spaced - could be log, or array tickvals, or nonuniform date ticks (months/years). Anyway it seems like a setting like tickmode = 'match overlay' could cover all of these cases: just look at where all the ticks of the main axis got drawn and put ticks in those same places on the matching axis. No need to ever calculate dtick or tick0.
Would it be hard to implement tickmode = 'match overlay'?
Probably not very hard, want to give it a try? Plotly folks are a bit busy for the foreseeable future...
I wish I had the time to dedicate, seriously, so I could give back to you guys for how you give to the community. Maybe I can tackle this in Feb/Mar 😭
Is there a fix so far?
@andy1547 @Braintelligence @qxlsz @alexcjohnson @ankuradhey
I’ve crafted a comprehensive solution. This was fairly rushed, so if there are any mistakes or confusions, please do let me know
https://github.com/VictorBezak/Plotly_Multi-Axes_Gridlines
@andy1547 @Braintelligence @qxlsz @alexcjohnson @ankuradhey
I’ve crafted a comprehensive solution. This was fairly rushed, so if there are any mistakes or confusions, please do let me know
https://github.com/VictorBezak/Plotly_Multi-Axes_Gridlines
@VictorBezak That's great. Thanks for that Victor. Trying it out now and it works well.
@pkozul I'm glad it's making use for you! Just wanted to let you know that the current version isn't yet working for all cases of data that contain fractional values between 0 and 1, or for data that contains negative values. I'm still working on the code that nicely covers all cases. I'll follow up when it's complete
@VictorBezak Sounds good. Having it work for fractional values will be a great enhancement, as a lot of the charts I'm working with contain a mixture of Y axes (i.e. one axis has large numbers in the millions, while the other axis has fractional numbers). Good luck (although I'm sure you won't need it)!
For Python users, I have adapted @VictorBezak 's solution. See: https://gist.github.com/mschrader15/ccf4c4e9b5b1254a7d6b38a92fd88560
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.
Sponsorship range: $10k-$15k
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.
This issue has been tagged with
NEEDS SPON$ORA 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.
Sponsorship range: $10k-$15k
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.
Hey, @jackparmer ! I'd be happy to sponsor this feature. I've reached out via Plotly's "Contact Us" form. Is there a more preferred mode of contact from which I could get more details? Thanks!
This issue has been tagged with
NEEDS SPON$ORA 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. Sponsorship range: $10k-$15k 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.
Hey, @jackparmer ! I'd be happy to sponsor this feature. I've reached out via Plotly's "Contact Us" form. Is there a more preferred mode of contact from which I could get more details? Thanks!
@jackparmer I'd love to help with the Python and Matlab integration. @VictorBezak should get 1st and 2nd dibs for the Plotly.js support though!