Closed racng closed 10 months ago
I am not sure whether this is a displaying issue, please check whether this issue is still here if you save it into pdf using savefig(**,bbox_inches='tight')
and open the pdf.
Saving as PDF didn't change the results. I realized this is caused by the fact that I used the basic ASTERISK U+002A * instead of U+2217 ASTERISK OPERATOR ∗. The basic asterisk sits higher.
I also had to change the font to Courier with annot_kws={'fontname':'Courier'}
Thanks for helping debug. Could you please paste your completed updated code here so that other users could potentially avoid such an issue?
Here is the code:
# Assuming you have a dataframe of heatmap values and another matrix of corresponding p-values
heatmap = ...
pval = ...
# Format stars for significance. Note we are using the asterisk operator.
def fmt_star(x):
if x >= 0.05:
return ' '
elif x < 0.05:
return '∗'
elif x < 0.01:
return '∗∗'
elif x < 0.001:
return '∗∗∗'
# Matrix of star annotation
star = pval.map(fmt_star)
# Plot heatmap with custom star annotation
# We pass additional keyword arugments to customize the font of the annotation
# Choose a monospaced typeface that can render the U+2217 ASTERISK OPERATOR ∗ (ex. Courier)
cm = pch.ClusterMapPlotter(
data=heatmap,
...,
annot=star, fmt=None, annot_kws={'fontname': 'Courier'},
)
Thanks. @racng
Is there a way to center custom annotation vertically ? In this example in the documentation, the asterisks are not centered vertically.