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

Annotation label & legends with spaces in the title #101

Open
mwe-bixeng opened this issue Nov 23, 2024 · 8 comments
Open

Annotation label & legends with spaces in the title #101

mwe-bixeng opened this issue Nov 23, 2024 · 8 comments

Comments

@mwe-bixeng
Copy link

Is there a way to set each row of the annotation with text that has spaces? In my example, I would like the legend title to say "Enrol Group" with a space between the words. And similarly for the label of the row. Or is there a way for title in legend_kws to overwrite the variable value?

I've tried using legend_kws={'color_text':False, 'title': "Enrol Group"} in anno_simple but because it's taking the variable name as the title and label, I get this error:

TypeError: matplotlib.axes._axes.Axes.legend() got multiple values for keyword argument 'title'

# variable = EnrolGroup which is the title in the legend and label of that row
col_ha = HeatmapAnnotation(EnrolGroup=anno_simple(df["Enrolment Group"],add_text=True,legend=True , legend_kws={'color_text':False, 'title': "Enrol Group"} plot=True,legend=True,legend_gap=3 , legend_order=True , label_side='left' )

Screenshot 2024-11-24 at 8 40 39 AM
@DingWB
Copy link
Owner

DingWB commented Nov 23, 2024

Thanks for your feedback, it has already been fixed. You can pass title to legend_kws now (you need to re-install from Github).
In addition, you can also pass a dict to HeatmapAnnotation so that the key can contain space, please see example here: https://dingwb.github.io/PyComplexHeatmap/build/html/notebooks/advanced_usage.html#Add-multiple-heatmap-annotations-using-for-loop

@mwe-bixeng
Copy link
Author

Thanks so much for such a quick response! I can confirm that using title in legend_kws works but I think that may have broken the label argument. I added both title and label and get this error:
TypeError: Legend.__init__() got an unexpected keyword argument 'label'

Same as above except I added label
col_ha = HeatmapAnnotation(EnrolGroup=anno_simple(df["Enrolment Group"],add_text=True,legend=True , legend_kws={'color_text':False, 'title': "Enrol Group", 'label':'Enrol Group label'} plot=True,legend=True,legend_gap=3 , legend_order=True , label_side='left' )

@DingWB
Copy link
Owner

DingWB commented Nov 24, 2024

Why did you add the parameter label? There is no such kind of argument label for legend_kws:
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html

@mwe-bixeng
Copy link
Author

I'm following the example link you gave in the previous message (advanced usage)
M1=anno_simple(df_cols['M1'],cmap='jet',legend=lgd,vmax=1,vmin=0,legend_kws={'label':'M1'}),
to change the side label text. the legend title has changed but not the side label. did I misunderstand your instruction?

@mwe-bixeng
Copy link
Author

Oh sorry, I misread which dict you meant. I see what I can do with using a dict into the Heatmap. thanks. But I think the above will still be confusing for others if there is no label directive but it's in the adv usage instructions. cheers

@DingWB
Copy link
Owner

DingWB commented Nov 24, 2024

I also added the parameter label to all annotation functions.
You can re-install the latest version from Github and try this parameter label.

@mwe-bixeng
Copy link
Author

Excellent! Now I can have 2 different texts for the label and legend. Thank you so much again for such a quick response and fix. Here's an example of where these changes have come in very handy. I used the dict method to change the label text.

col_ha_dict = {"Cancer predisposition": anno_simple(df["Cancer predisposition"] , colors={'Yes': 'purple'} , legend_kws={'color_text':False, 'title': "Identification of a \npreviously unknown \ncancer predisposition"} , add_text=False,legend=True)}

col_ha = HeatmapAnnotation(**col_ha_dict , axis=1 , plot=True,legend=True,legend_gap=3 , label_side='left' )
Screenshot 2024-11-25 at 12 46 50 PM

@DingWB
Copy link
Owner

DingWB commented Nov 25, 2024

You don't have to pass a dict to HeatmapAnnotation, you can set parameter label with the latest version.

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

No branches or pull requests

2 participants