Created
April 27, 2024 01:06
-
-
Save MNoichl/0becd1009f91241885ff8cd901b0d4c2 to your computer and use it in GitHub Desktop.
Proposed way to set label-sizes for datamapplot with pylabeladjust.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import textwrap | |
from sklearn.preprocessing import MinMaxScaler | |
df['wrapped_label'] = [textwrap.fill(label, width=20) for label in df['label']] | |
# Set the font-size range: | |
scaler = MinMaxScaler(feature_range=(3,28)) | |
#set the rescaling-value | |
rescaling_value = 0.9 | |
df['size'] = scaler.fit_transform(np.array([value ** rescaling_value for value in df['count']]).reshape(-1,1)) | |
# set percentage cut-off for bold: | |
cut_off_bold = 80 | |
df['style'] = ["bold" if x >= np.percentile(df['count'], cut_off_bold) else "normal" for x in df['count']] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment