Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

legend not show #98

Open
wahaha233333 opened this issue Nov 15, 2024 · 11 comments
Open

legend not show #98

wahaha233333 opened this issue Nov 15, 2024 · 11 comments

Comments

@wahaha233333
Copy link


df = pd.DataFrame(['GroupA'] * 5 + ['GroupB'] * 5, columns=['AB'])
df['CD'] = ['C'] * 3 + ['D'] * 3 + ['G'] * 4
df['EF'] = ['E'] * 6 + ['F'] * 2 + ['H'] * 2
df['F'] = np.random.normal(0, 1, 10)
df.index = ['sample' + str(i) for i in range(1, df.shape[0] + 1)]
df.head()
df_heatmap = pd.DataFrame(np.random.randn(30, 10), columns=['sample' + str(i) for i in range(1, 11)])
df_heatmap.index = ["Fea" + str(i) for i in range(1, df_heatmap.shape[0] + 1)]
df_heatmap.iloc[1, 2] = np.nan

plt.figure(figsize=(3.5, 6))
cm = pch.ClusterMapPlotter(data=df_heatmap,
col_cluster=True,row_cluster=True,
col_split=df.AB,row_split=2,
col_split_gap=0.5,row_split_gap=0.8,
label='values',row_dendrogram=True,
show_rownames=True,show_colnames=True,
row_names_side='right',
tree_kws={'row_cmap': 'Set1','colors':'blue'},verbose=0,legend_gap=5,
cmap='RdYlBu_r',xticklabels_kws={'labelrotation':-90,'labelcolor':'blue'})
plt.savefig("example0.pdf", bbox_inches='tight')
plt.show()


version: 1.7.9
python: 3.11.0
matplotlib: 3.9.2

this is what i got

image

@DingWB
Copy link
Owner

DingWB commented Nov 15, 2024

I ran the same code, and everything is good.
Can you test different versions of Python and matplotlib and help find the issue?

@winglet0996
Copy link

winglet0996 commented Nov 18, 2024

The same issue as @wahaha233333, I didn't see the legend with the code above.

  • pycomplexheatmap: 1.7.9
  • python: 3.9.20
  • matplotlib: 3.9.2

@DingWB
Copy link
Owner

DingWB commented Nov 18, 2024

Hi @winglet0996
Thanks for your feedback; it is helpful.
Indeed, there was something wrong with the PyPI 1.7.9. But no problem on the GitHub.
So, I released a new version, 1.8.0. You can either upgrade to 1.8.0 using pip or directly install from github pip uninstall -y PyComplexHeatmap && pip install git+https://github.com/DingWB/PyComplexHeatmap

@DingWB
Copy link
Owner

DingWB commented Nov 18, 2024

Please let me know whether it works or not @wahaha233333 @winglet0996

@winglet0996
Copy link

That helps! Thanks a lot for your quick reply.

@wahaha233333
Copy link
Author

It works!, thank you so much.

@mwe-bixeng
Copy link

I have a related issue I think. I cannot see the bottom of the plots and I need to keep changing the figure size to see the legend using the code in https://dingwb.github.io/PyComplexHeatmap/build/html/notebooks/get_started.html#2.-Plot-heatmap-annotations
code block = [11]

Version 1.8.1.post2
Python 3.12.7
Matplotlib 3.7.5

figsize = 3,4 (exact example code)
figsize3_4

increase width (8,4) => can start to see the legend but the image is now scaling as well
figsize_8_4

@DingWB
Copy link
Owner

DingWB commented Nov 25, 2024

You ran the code in Pycharm or Jupiter?
How can I reproduce this issue?

@mwe-bixeng
Copy link

Pycharm equivalent - macOS using venv. I used the codeblock [11] in this example: https://dingwb.github.io/PyComplexHeatmap/build/html/notebooks/get_started.html#2.-Plot-heatmap-annotations
and cannot see the full image + legend.

Version 1.8.1.post2
Python 3.12.7
Matplotlib 3.7.5

@DingWB
Copy link
Owner

DingWB commented Nov 25, 2024

What if you save it to a PDF?

@DingWB
Copy link
Owner

DingWB commented Nov 25, 2024

Please try plt.tight_layout() and save to pdf (plt.savefig("example.pdf", bbox_inches='tight')) before plt.show

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants