Skip to content
Ilya Flyamer edited this page Feb 11, 2018 · 7 revisions

About

This simple library lets you automatically adjust text position on matplotlib plots to avoid or minimize overlaps - with other individual text labels, or with some specified coordinates (for example, the original text coordinates to simplify labelling scatter plots), or most arbitrary matplotlib objects such as bars or the legend (however their bounding boxes are used, not the actual object edges, so with non-rectangular objects it won't work quite that nicely).

Getting started

Installation and examples

To use the library, you can simply install it from pypi (pip install adjustText) or directly from GitHub (pip install https://github.com/Phlya/adjustText/archive/master.zip) and import the main function like this: from adjustText import adjust_text. A number of different examples are available as a reproducible Jupyter Notebook in this repository (https://github.com/Phlya/adjustText/blob/master/examples/Examples.ipynb) together with the example data used there (https://github.com/Phlya/adjustText/tree/master/examples).

Using the library

Using the adjust_text function for simple plots is very easy, while for complicated plots it is quite configurable. The minimal call signature only requires a list of matplotlib.text.Text objects. With no other other arguments, it will move those objects to avoid overlaps between all of them, and with their original positions - this makes it super easy to quickly annotate a scatter plot without hiding the data.

A simple example: import matplotlib.pyplot as plt # Matplotlib 2.0 shown here from adjustText import adjust_text import numpy as np

Clone this wiki locally