TutteInstitute / datamapplot

Creating beautiful plots of data maps
MIT License
747 stars 47 forks source link

Differences in marker size lost on zoom #36

Open zilch42 opened 2 months ago

zilch42 commented 2 months ago

I wonder if there was a different way to apply the marker_size_array so that the difference is in point size can, at least to some degree, be maintained at different zoom levels. In the example below I've generated some lognormal marker size data which more closely resembles my use case.

import numpy as np
import datamapplot

wikipedia_data_map = np.load("wikipedia_layered_data_map.npy")
wikipedia_label_layers = []
for i in range(6):
    wikipedia_label_layers.append(
        np.load(f"wikipedia_layer{i}_cluster_labels.npy", allow_pickle=True)
    )
wikipedia_hover_text = [
    x.strip()
    for x in open(
        "wikipedia_large_hover_text.txt",
        mode="r"
    )
]
wikipedia_marker_size_array = np.load("wikipedia_marker_size_array.npy")
log_normal_data = np.random.lognormal(0, 1, len(wikipedia_marker_size_array))
log_normal_data = 1 + (log_normal_data - log_normal_data.min()) * (70 - 1) / (log_normal_data.max() - log_normal_data.min())

plot = datamapplot.create_interactive_plot(
    wikipedia_data_map,
    wikipedia_label_layers[0],
    wikipedia_label_layers[1],
    wikipedia_label_layers[3],
    wikipedia_label_layers[5],
    hover_text = wikipedia_hover_text,
    title="Map of Wikipedia",
    sub_title="Paragraphs from articles on Simple Wikipedia embedded with Cohere embed",
    logo="https://asset.brandfetch.io/idfDTLvPCK/idyv4d98RT.png",
    font_family="Marcellus SC",
    background_color="#eae6de",
    marker_size_array=log_normal_data,
    cluster_boundary_polygons=True,
    initial_zoom_fraction=0.4,
    point_radius_max_pixels=16,
)
plot

When zoomed out there are big differences in the marker sizes which generally piques a user's interest (see highlighted MERS document). image

But upon zooming in to investigate, the large point is hard to find because it looks the same as all the others. image

I understand the way the point_radius_mix_pixels and point_radius_max_pixels are being applied, and it does feel natural for the points to get bigger as you zoom in, but I wonder if there is a way that some measure of differentiation can be maintained at those deeper zoom levels?

lmcinnes commented 2 months ago

It may be possible in principle, but I am learning very heavily on deck.gl and the features they support, and in that case it is not so easy. The best you can do is not have the points get larger as you zoom in. You can arrange for that by messing with the radiusUnits and setting it to "pixels" instead of "common". You may have to then mess with radiusScale or rescale your marker sizes but that should work. Personally I found the result of this underwhelming, but your mileage may vary.