Skip to content

Support Plotly axis scaleanchor and scaleratio? #34

@mars0i

Description

@mars0i

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions