Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Fixed scale anchor for initial layout but not fixed during zoom

I’m trying to have the y and x axis for a scatterplot have the same scale when the graph is first displayed. However, upon zooming, I would like for the user to not be constrained to only fixed ratio zooms. Currently the scaleanchor attribute is great for the initial display but zooms are also fixed. What workarounds are there around this?

Hi @nicolascage,

You’re right that that scaleratio property is designed to constrain the zoom level as well. You should be able to set up the initial proportions using:

  1. fig.layout.width and fig.layout.height to set the overall figure width/height
  2. The l, r, t, b, properties of fig.layout.margin to set the spacing between the outer edge of the plotting area and the outside of the figure.
  3. range property of fig.layout.xaxis and fig.layout.yaxis to set the axis range extents.

So the aspect ratio of your plotting area (in screen coordinates) will be

(width - margin.l - margin.r)/(height - margin.t - margin.b)

Then you can set the ratio between the xaxis.range and yaxis.range to be some factor times this aspect ratio:

factor*(width - margin.l - margin.r)/(height - margin.t - margin.b)=
    (xaxis.range[1] - xaxis.range[0])/(yaxis.range[1] - yaxis.range[0])

Hope that helps get you started!

Hi @jmmease. Thanks for the detailed and quick response as usual. I look forward to trying this out, and will let you know how it turns out!

1 Like