Jupyter Scatter gets support for text labels
New version of Jupyter Scatter is out! š„³ Adding long-overdue support for text labels that make it easier to correlate points with your underlying data.
Designing a generic DataFrame-driven method that integrates with Jupyter Scatterās overall API design was a fun challenge. I ended up modeling the label assignment via categorical/string columns, which groups points and shows a single text label per group. Point labels are also supported and you can assign as many label types as you need.
To learn how to use the new labeling feature see:
- Code: https://github.com/flekschas/jupyter-scatter
- Docs: https://jupyter-scatter.dev/labels
- Demos: https://github.com/flekschas/jupyter-scatter-tutorial/blob/main/notebooks/6-Labels.ipynb
The label placement is implemented using a dynamic map labeling approach to avoid over-plotting while maximizing the labels that can be shown across zoom levels. Label positions are computed upfront for performant rendering and can be persisted as parquet files for fast re-use. Additionally, the label data is tiled to allow limiting the total number of labels per tile and enable scaling to hundreds of thousands of labels.
Some fantastic libraries I learned about and use for labeling:
- Jeffrey Heerās Flechette is a fast and lightweight library for loading Apache Arrow. Jupyter Scatter uses it to send label information between Python <> JS kernels as binary data. Flechette is perfect for this! Really nice work Jeff. š
- Kyle Barronās geoindex is a fast, memory-efficient, zero-copy spatial indexing library for Python. Essentially the counterpart to Volodymyr Agafonkinās fantastic KDBush which weāre using under the hood in regl-scatterplot already for statically indexing 2D points. š
- Rye Terrellās awesomeCandygraph library for plotting 2D charts with WebGL heavily inspired our text measurement implementation. Efficiently and precisely measuring the labelsā dimensions is critical for handling many text labels. š
- Thilo Spinnerās Colormap 2D is a library implementing various 2D color maps from Steiger et al.ās (2015) āExplorative analysis of 2D color mapsā. 2D color maps are an excellent way to color points in data maps with many categories/groups/labels. š
Finally, shoutouts to Trevor Manz for reviewing the quite involved PR and Leland McInnesā wonderful DataMapPlot library which inspired the 2D color map integration and has many excellent shared examples. š
Let me know what you think and happy scatter plot labeling š·ļø