hclust2_ValueError: Passing a Normalize instance simultaneously with vmin/vmax is not supported. Please pass vmin/vmax directly to the norm when creating it

Hi am trying to develop heatmap plot using hclust2 for my data.

I updated latest versions of matplotlib to latest version 1.6.1. Having issue vmin/vamx. Command line and error out as follows. Please help me to fix this issue

hclust2.py
-i merged_abundance_table_species.txt
-o metaphlan_abundance_heatmap_species.png
–f_dist_f braycurtis
–s_dist_f braycurtis
–cell_aspect_ratio 0.5
–log_scale
–flabel_size 10 --slabel_size 10
–max_flabel_len 100 --max_slabel_len 100
–minv 0.1
–dpi 300

Traceback (most recent call last):
File “/Users/nareshmutha/opt/anaconda3/bin/hclust2.py”, line 825, in
hclust2_main()
File “/Users/nareshmutha/opt/anaconda3/bin/hclust2.py”, line 822, in hclust2_main
hm.draw()
File “/Users/nareshmutha/opt/anaconda3/bin/hclust2.py”, line 678, in draw
im = ax_hm.imshow( self.numpy_matrix, #origin=‘lower’,
File “/Users/nareshmutha/opt/anaconda3/lib/python3.9/site-packages/matplotlib/_api/deprecation.py”, line 454, in wrapper
return func(*args, **kwargs)
File “/Users/nareshmutha/opt/anaconda3/lib/python3.9/site-packages/matplotlib/init.py”, line 1423, in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
File “/Users/nareshmutha/opt/anaconda3/lib/python3.9/site-packages/matplotlib/axes/_axes.py”, line 5609, in imshow
im._scale_norm(norm, vmin, vmax)
File “/Users/nareshmutha/opt/anaconda3/lib/python3.9/site-packages/matplotlib/cm.py”, line 436, in _scale_norm
raise ValueError(
ValueError: Passing a Normalize instance simultaneously with vmin/vmax is not supported. Please pass vmin/vmax directly to the norm when creating it.

Hi @nareshmvr
Your problem might be due to a newer version of matplotlib that do not support anymore the min/max requirements. I would suggest to downgrade your matplotlib version to 1.5.3 and try again

Hi Aitor,

Thank you very much for the response. I even tried matplotlib v1.5.3 initially then I upgraded it to the latest version. It worked ignoring params --minv and log scale.

I generated heatmap with R using this data :slight_smile:

Hello,
I’m sorry to post another bug with MetaPhlAn4.
I have merged the profiles.txt output from the example data (without the ‘stool’ output; see other post) and followed your tutorial to generate heatmaps. I get the following error message at the hclust2.py step.
(conda list >> shows this for matplotlib: matplotlib-base 3.7.1 py310he60537e_0 conda-forge)
I am not sure whether the previous suggestion in this post (downgrade matplotlib) is really that best way to solve this issue;

hclust2.py -i merged_abundance_table_species.txt -o metaphlan4_abundance_heatmap_species.png --f_dist_f braycurtis --s_dist_f braycurtis --cell_aspect_ratio 0.5 --log_scale --flabel_size 10 --slabel_size 10 --max_flabel_len 100 --max_slabel_len 100 --minv 0.1 --dpi 300
/home/bt140047/miniconda3/envs/metaphlan4/bin/hclust2.py:518: MatplotlibDeprecationWarning: The register_cmap function was deprecated in Matplotlib 3.7 and will be removed two minor releases later. Use matplotlib.colormaps.register(name) instead.
pylab.register_cmap(name=n,cmap=my_cmap)
Traceback (most recent call last):
File “/home/bt140047/miniconda3/envs/metaphlan4/bin/hclust2.py”, line 825, in
hclust2_main()
File “/home/bt140047/miniconda3/envs/metaphlan4/bin/hclust2.py”, line 822, in hclust2_main
hm.draw()
File “/home/bt140047/miniconda3/envs/metaphlan4/bin/hclust2.py”, line 678, in draw
im = ax_hm.imshow( self.numpy_matrix, #origin=‘lower’,
File “/home/bt140047/miniconda3/envs/metaphlan4/lib/python3.10/site-packages/matplotlib/init.py”, line 1442, in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
File “/home/bt140047/miniconda3/envs/metaphlan4/lib/python3.10/site-packages/matplotlib/axes/_axes.py”, line 5670, in imshow
im._scale_norm(norm, vmin, vmax)
File “/home/bt140047/miniconda3/envs/metaphlan4/lib/python3.10/site-packages/matplotlib/cm.py”, line 418, in _scale_norm
raise ValueError(
ValueError: Passing a Normalize instance simultaneously with vmin/vmax is not supported. Please pass vmin/vmax directly to the norm when creating it.

Hi @ARW-UBT by the error you are reporting, downgrading matplotlib seems the best way to fix the issue