/plotannot

A small python library to adjust and annotate axis ticklabels in plots.

Primary LanguagePythonMIT LicenseMIT

plotannot

PyPI Version

Introduction

plotannot is a a python package to automatically highlight and adjust overlapping ticklabels in matplotlib/seaborn plots. It is written with great inspiration and appreciation for the statannot package (webermarcolivier/statannot - now maintained at trevismd/statannotations), as well as the adjustText package (Phlya/adjustText).

I originally created this package for myself, as I wanted to create ComplexHeatmap (R package) style annotations for Python plots - but maybe it is of use to you too?

Features

  • Add annotation lines for certain row/column labels
  • Shift labels to not overlap
  • Add additional highlights such as color, fontsize, etc. to certain row/column labels

Getting started

Install from PyPI:

pip install plotannot

Or directly from github:

pip install git+git://github.com/msbentsen/plotannot

Requirements for package:

  • Python >= 3.6
  • matplotlib
  • numpy

Simple example

import pandas as pd
import seaborn as sns
import plotannot

#Plot heatmap
table = pd.DataFrame(np.random.random((100,50)))
ax = sns.heatmap(table, xticklabels=True, yticklabels=False)

#Rotate all labels
plotannot.format_ticklabels(ax, axis="xaxis", rotation=45)

#Annotate labels
to_label = range(20,35)
plotannot.annotate_ticks(ax, axis="xaxis", labels=to_label) 

#Color individual labels
plotannot.format_ticklabels(ax, axis="xaxis", labels=[25], color="red")

Additional examples are found in the examples notebook.

Documentation and help

Documentation of the main functions are found at: plotannot.readthedocs.io. Examples of how to use these are in the examples notebook here: examples/examples.ipynb.

Issues and PRs are very welcome - please use the repository issues to raise an issue/contribute.