jupyter-scatter-tutorial icon indicating copy to clipboard operation
jupyter-scatter-tutorial copied to clipboard

y scale zoom modifier / aspect ratio control

Open declann opened this issue 10 months ago • 3 comments

I have scatters with a handful of extreme values on the Y axis.

I can zoom into all points but with no control over the aspect ratio so it's usually difficult to get a view that gives good context.

I think it would be useful if SHIFT + mousewheel zoomed the Y axis exclusively, thereby giving users control over the aspect ratio and exactly what they want to view + context.

I'm not sure if there is a programmatic way to set the aspect ratio or scale extents, but I still think it's better if there is a user-facing control.

P.S. I love this widget!

declann avatar May 04 '25 18:05 declann

You can adjust the aspect ratio to your liking. The two main ways to control it are the x and y scales and the view aspect ratio. The former control the scale at which the data is drawn and the second literally controls the view aspect ratio.

By default, the x and y range are scaled such that their extents are drown on a 1:1 visual scale. What does this mean, say your x data ranges from 0 to 1 and your y data ranges from -100 to 1000. If your width is 200 and your height is 100, the data is rescales such that 100px on the x axes reflect [0, 1] and 100px on the y axes reflect [-100, 1000]. If you want to adjust the range that 100px reflect, use the x and y axis. For instance if you want to have 100px reflect [0, 10] on both the x and y axis you can do

common_scale = (0, 10)
Scatter(x_scale=common_scale, y_scale=common_scale)

If you additionally want to change the aspect ratio such that 200px on the x axis reflect [0, 10] you can do

width = 200
height = 100
Scatter(options={'aspectRatio': width / height})

Does this help with your specific case?

flekschas avatar May 05 '25 01:05 flekschas

Hey @flekschas thanks a lot for the response and details! Certainly that helps me setup a better aspect ratio for particular scatters - especially for presentations where I know what data I'll use.

Data to my scatter is generally dynamic though - and coding ratios adds friction, so I also think it would be nice if the user had some control to change the aspect ratio, by shift+wheel to scale the y axis only.

I faced a similar issue in this visual: https://actuarialplayground.com/ which I use in many different contexts where users will want to zoom into different bits, and I think the behavior effectively gives the user control of what they see

But, it's up to you to consider if it's relevant/necessary users of jupyter-scatter!

declann avatar May 10 '25 19:05 declann

I totally see your point and I think this would indeed be a neat feature. Technically, the camera scaling is already modeled as a tuple, so it should be possible to zoom axes independently. However, I would need to refactor regl-scatterplot a bit to actually be able to handle axes-individual scales as right now the library defaults to just justing the x-scale factor assuming that both scales are identical.

flekschas avatar May 13 '25 13:05 flekschas