This is a test version of Biostars. For the public version, visit https://www.biostars.org.
how to adjust the length of y axis

There are 10000+ samples in my data. I tried to get the heatmap using cnvkit, but the sample names in the y axis are overlapped each other. How can I adjust the length of the y axis and display all the sample names?

here is my commandline:

cnvkit = /software/cnvkit-0.9.6/cnvkit.py

python3 $cnvkit heatmap *IM3.cns -o IM3.png

IM3

cnvkit heatmap cnv

Do you want 10000+ sample names in the figure? Do you mean legible (readable)?

1 answer

Check out Customizing plots and issue196:

Good point. The quick workarounds are:

A. Run the heatmap command without -o to generate an interactive plot, then expand that plot to the full size of your screen and use the plot window's save button to save the plot in your preferred format.

B. Use a matplotlibrc file to change the default font size.

C. Use cnvlib.do_heatmap to generate an interactive plot, then get the current axis and modify the font size with matplotlib.pyplot (and change anything else you like). The ipython/jupyter notebook is handy for this.

The documentation could be more clear on this.

A. I used the cnvkit on the linux system, so I can't generate an interactive plot.

B. I have tried this by add a .matplotlibrc file in the file"cnvkit.py" directory, but the font size didn't change.

C. I also tried, here is my script file:

*from glob import glob

from matplotlib import pyplot as plt

import cnvlib

segments = [cnvlib.read(f) for f in glob("/data2/gminix/project_new/fangling/cnv_heatmap/P-00001*.IM3.cns")]

ax = cnvlib.do_heatmap(segments)

ax.set_title("All my samples")

plt.rcParams["font.size"] = 3.0

plt.savefig("/data2/gminix/project_new/fangling/cnv_heatmap/try.png")

plt.show()*

and I run the script and return the error message:

**/software/cnvkit-0.9.6/cnvlib/heatmap.py:25: UserWarning: Attempting to set identical bottom==top results

in singular transformations; automatically expanding.

bottom=0, top=0

axis.set_ylim(0, len(cnarrs))**

Hi shengkeyuan111,

To increase the height of cnvkit.py heatmap, (A) works for me if using X11 forwarding; (B) works for me by creating a custom matplotlibrc file before plotting:

# Get example
wget -nc https://raw.githubusercontent.com/etal/cnvkit/master/test/formats/tr95t.cns

# Make some copies of it as different samples
mkdir -p samples
for i in $(seq 1 100); do cp tr95t.cns samples/tr95t_${i}.cns; done

# Create custom setting
mkdir -p ~/.config/matplotlib
echo "figure.figsize: 6.4, 20" > ~/.config/matplotlib/matplotlibrc

# Generate heatmap
cnvkit.py heatmap samples/tr95t_*.cns -o tr95t.png

More parameters can be found at https://matplotlib.org/users/customizing.html

long_heatmap

Wa, it works for me. I was troubled with the problem for two days. Thank you so much!

Log in to answer this question.