sbslee / dokdo

A Python package for microbiome sequencing analysis with QIIME 2
https://dokdo.readthedocs.io
MIT License
42 stars 12 forks source link

Overlapping legends on clustermap #51

Closed rupesh-sinha closed 1 year ago

rupesh-sinha commented 1 year ago

Hi @sbslee I was plotting a cluster map using the following command on a .csv file that contains relative frequency of top20 bacterial class.

import pandas as pd
import dokdo
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set()
df = pd.read_csv(csv_file, index_col=0)
dokdo.clustermap(df,
              metadata=metadata_file,
              normalize='clr',
              hue1='matrix',
              figsize=(10, 8)
              )
plt.savefig('heatmap-3.png')

and got this image

image

Can you suggest how to plot the legends and scale so that it doesn't overlap on the fig? Also when I am using flip=True the color code of samples are going missing from the graph: image

Please help!

sbslee commented 1 year ago

@rupesh-sinha,

Great questions! As for the first question, you can simply make the figure bigger with, say, figsize=(20, 20). This should spread things out.

As for the other question, congratulations, you found a bug! I will try to fix this issue in the next release (1.16.0).

Thanks for reporting the issues.

sbslee commented 1 year ago

https://stackoverflow.com/questions/71871308/seaborn-clustermap-and-multiple-color-labeling-of-columns

sbslee commented 1 year ago

@rupesh-sinha,

FYI, the bug has been fixed in the 1.16.0-dev branch. I will release the official version soon, but in the meantime you are welcome to try it out!

import dokdo
import matplotlib.pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set()
qza_file = '/Users/sbslee/Desktop/dokdo/data/moving-pictures-tutorial/table.qza'
metadata_file = '/Users/sbslee/Desktop/dokdo/data/moving-pictures-tutorial/sample-metadata.tsv'

dokdo.clustermap(qza_file,
                 metadata=metadata_file,
                 normalize='clr',
                 hue1='body-site',
                 hue2='subject')

without-flip

dokdo.clustermap(qza_file,
                 metadata=metadata_file,
                 normalize='clr',
                 flip=True,
                 hue1='body-site')

with-flip