Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert non overlapping text in matplotlib?

I am trying to insert power flow results in a network plot created with matplotlib. Some buses are so close that labelling the names along with power flow results is proving to be a big headache because text overlap is making some portions unreadable.

Is there some way to use the bounding box of the text to determine whether the text overlaps the plot lines and/or some other text?

like image 204
amaity Avatar asked Nov 18 '12 03:11

amaity


1 Answers

This is no simple answer to this problem, as it's an example of the automatic label placement problem, which is NP-hard (i.e. there are no fast algorithmic approaches which are guaranteed to solve this). Not even Google and OpenStreetMaps have perfected solutions to this!

Potential solutions can include hiding the connections or labels for less important elements, rendering a series of images each of which contains a subset of the labels/connections, and rendering images at different zoom levels. The Sklearn tutorial on visualizing the stock market structure has a good example for some simple heuristic approaches for label placement.

You may also want to poke around the GIS stack exchange, as similar questions have been asked there.

like image 147
emunsing Avatar answered Sep 30 '22 09:09

emunsing