Ann-Holmes / pheatmap

pheatmap for Python
BSD 3-Clause "New" or "Revised" License
2 stars 0 forks source link

[Feature request]: Allow adjustment of annotation bar text size #11

Open mnshgl0110 opened 1 year ago

mnshgl0110 commented 1 year ago

Hi, First of all, thanks for developing this package. I am finding it super efficient and useful. I would like to request that the package allows manual adjust of the annotation bar text size. Currently, it is hard-coded to be size=6 in the line below. https://github.com/Ann-Holmes/pheatmap/blob/60e84b8b1a9e706d15b09e0e2f0a212ebf178f3c/src/pheatmap/_annotation.py#L149

Thanks Manish

Ann-Holmes commented 1 year ago

I am glad to see that the pheatmap can be helpful. And I have added this parameter in the latest released pheatmap 1.0.1.

You can modify the font size of Annotationbar's names by annotation_row_names_style or annotation_col_names_sytle parameters. For example:

import numpy as np
import pandas as pd
from pheatmap import pheatmap

import matplotlib as mpl
mpl.rcParams['figure.dpi'] = 300

nrows, ncols = 10, 10
mat = np.linspace(-1, 1, nrows * ncols).reshape(nrows, ncols)
rownames = ["abcdefghig"[i % 10] for i in np.arange(nrows)]
colnames = ["xyz"[i % 3] for i in np.arange(ncols)]

mat = pd.DataFrame(mat, index=rownames, columns=colnames)

anno_row = pd.DataFrame(dict(
    anno1=np.linspace(0, 10, nrows),
    anno2=["CNS"[i % 3] for i in np.arange(nrows)]
))
anno_col = pd.DataFrame(dict(
    anno3=np.linspace(0, 20, ncols),
    anno4=["ABC"[i % 3] for i in np.arange(ncols)]
))

anno_row_cmaps = {"anno1": "Blues", "anno2": "Set1"}
anno_col_cmaps = {"anno3": "Purples", "anno4": "Set3"}

fig = pheatmap(
    mat, annotation_row=anno_row, annotation_col=anno_col,
    annotation_row_cmaps=anno_row_cmaps, annotation_col_cmaps=anno_col_cmaps,
    annotation_row_names_style=dict(size=8, family="Times New Roman"),
    annotation_col_names_style=dict(size=8, family="Times New Roman"),
    show_annotation_col_names=True
)

You can also modify more font's attributes, such as font family. In the above example, I set the font family as "Times New Roman".

If you are interested in pheatmap, welcome to pull requests.

Best wish!