plot.js and d3.js: The density of the density map is recalculated every time it is scaled

Hello, all
When I was using d3 and plot to implement Zoom functionality, I found that the density of the density map was recalculated every time I scaled it. May I ask if there were any errors in my code? Can you tell me the correct code if my code is incorrect? If there are no issues with my code, can this situation be avoided?
My notebook: Plot: Attempts on Zoom / Cui's Workspace | Observable

First, I’d suggest to use a d3.scaleLinear instead of UTC, it would avoid the “trembling” you see.

Plot’s density mark is computed in the projected space, so it’s not surprising that the shapes change when you change the x scale. I would say that your code is correct, but it’s not aligned with your expectation :slight_smile:

If you want to compute densities in data space instead, you could use d3.contourDensity, then display the results with a Plot.geo mark.

1 Like

Okay, I understand. Thank you for your help. :smile: