Plotannot
A small python library to adjust and annotate axis ticklabels in plots.
Install / Use
/learn @msbentsen/PlotannotREADME
plotannot
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?
<img src="examples/before_after.png"/>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")
<img src="examples/simple_example.png"/>
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.
Related Skills
node-connect
345.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
104.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
345.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
345.4kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
