Skip to content
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

Support Plotly axis scaleanchor and scaleratio? #34

Open
mars0i opened this issue Mar 7, 2025 · 0 comments
Open

Support Plotly axis scaleanchor and scaleratio? #34

mars0i opened this issue Mar 7, 2025 · 0 comments

Comments

@mars0i
Copy link
Member

mars0i commented Mar 7, 2025

I think it would be useful to support the Plotly.js scaleanchor and scaleratio properties in some way. There's a toy clojure illustration here.

A common use for me, recently, is to set the ratio to 1:

(-> plot
    plotly/plot
    (assoc-in [:layout :yaxis :scaleanchor] :x)
    (assoc-in [:layout :yaxis :scaleratio] 1)))

This forces the plot to treat differences between quantities in the $x$ and $y$ directions to display as equal distances: the visual units are the same in both directions. Plotly doesn't necessarily do this by default.

Image

A scaleratio of 1 is useful when plotting mathematical equations. For example, it may be important to know whether the slope of a curve is above or below 1. :scaleratio 1 means that a line with slope equal to 1 displays as a line at a 45 degree angle, as one would expect. In the image above, one can see immediately that the green line from lower left to upper right is $y=x$. More importantly, I can see immediately that the absolute value of the slope of the curved orange line is less than 1 where it crosses the $y=x$ line. (This matters in my current use.)

That's my recent use case, but :scaleratio 1 could also be useful in some cases for quick visual inspection of regressions and other curve-fitting.

One option would be to have a keyword with a boolean value to set the ratio to 1, or to leave it to vary. I don't currently have any uses for :scaleratios other than 1.

However, I could imagine that someone might want some other ratio, for example if distances in the $x$ and $y$ directions represent some domain-specific distances that viewers will intuitively understand. If that's worth supporting, then I am not sure whether it would be worthwhile for supporting the full functionality of scaleanchor and scaleratio, rather than only allowing the value of scaleratio to vary, in a use like that that I illustrate above. The full functionality of scaleanchor and scaleratio allows one to use alternative axes, but that's more confusing (I don't fully understand it yet), and there's always the fallback of using assoc-in.

I don't have strong opinions about the best way to do this.

(By the way, I have never figured out how to do this in Vega-lite. There are methods that seem like they should work, but they don't consistently do so. Vega-lite sets the ratios the way it wants. The fact that Plotly allows forcing the visual ratio to 1 is the main reason I'm rewriting some Vega-lite code for use with Tableplot Plotly.)

@mars0i mars0i changed the title Support axis scaleanchor and scaleratio Support axis scaleanchor and scaleratio? Mar 7, 2025
@mars0i mars0i changed the title Support axis scaleanchor and scaleratio? Support Plotly axis scaleanchor and scaleratio? Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant