altair
altair copied to clipboard
text position and repel on map
Hi,
Thanks for developing Altair! Finally a great tool for visualization using the grammar of graphics in python! I am really having a lot of fun with it!
I am visualizing a map using mark_geoshape
. I am adding points to the map using mark_point
, and corresponding labeling text using mark_text
. I have two issues:
- The text is not always close to the corresponding point. I use
x = "longitude:Q", y = "latitude:Q"
both inmark_point
andmark_text
. As an example, see the distance between the green dot and the green text in the figure attached; - Texts often overlap - see the pink and brown texts in the figure attached. Is there any function similar to ggrepel in ggplot?
Thank you very much again for such a great tool! Serena

No, I'm not aware of any functionality to automatically prevent text overlap. It would be worth a feature request in Vega-Lite.
@domoritz I think in theory this would be addressed by https://github.com/vega/vega-label, right? Are there plans to just integrate that work into the core vega story?
Yes and yes. We are working on getting it into Vega and then Vega-Lite. I can't promise a release date yet, though.
Looking forward!!!
@chanwutk
Yes, we are working on getting Vega-Label shipped in Vega. The plan is, then, to add the feature to Vega-Lite. :)
This feature was implemented? I have a similar problem on my plots.
No, it has not been implemented yet as far as I am aware.
It has been implemented and we are in the process of releasing the feature in Vega. The code is already in master at https://github.com/vega/vega/tree/master/packages/vega-label. Once we have support in Vega, we can support it in Vega-Lite as well. I can't promise a release date yet but it's coming. Thanks for your patience. It's a big feature to add with a lot of moving parts.
Ok! Thank you for the reply :)
That's a great piece of news! Thanks and looking forward!
@jakevdp It looks like vega implemented a label transform in version 5.16. Is there a way to pass transform data that hasn't officially been implemented in altair yet?
https://vega.github.io/vega/docs/transforms/label/
Thanks!
@chanwutk is working on bringing labeling to Vega-Lite at which point we can add it to Altair as well.
Hello@jakevdp, Any update on how to prevent the text overlap. Thank you very much in advance.
@arjunkumarp9 This was recently merged into Vega-Lite and will be in a future version of Altair.
@joelostblom could you please share some example to avoid the overlapping labels. Thank you very much in advance.
@arjunkumarp9 There are some VegaLite examples in the PR I linked above. As I mentioned, this feature is not available yet for Altair.
Note that we reverted the pull request to make sure the API is the best it can be and to make sure the docs are up to date as well. Please follow https://github.com/vega/vega-lite/pull/7378.
Closing this as it is an upstream issue and there is nothing to do on the Altair side of things. When https://github.com/vega/vega-lite/pull/7378 is merged, this will be in a following altair release