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

In my project, there are Chinese characters, and when I use the creat_plot() method to create a chart, the characters appear as garbage. #50

Open
superseanyoung opened this issue Nov 13, 2024 · 4 comments

Comments

@superseanyoung
Copy link

datamapplot.create_plot(reduced_embeddings, doc_name)

@superseanyoung
Copy link
Author

import matplotlib.pyplot as plt

设置中文字体

plt.rcParams['font.sans-serif'] = ['SimHei']

设置中文显示

plt.rcParams['axes.unicode_minus'] = False
Even using this code, I cannot solve the problem of garbled text.

@lmcinnes
Copy link
Contributor

I'm afraid I can't be much help with this. The static plots rely on matplotlib's annotate function to render the text, so we are somewhat at the mercy of matplotlib's rendering. Ideally there would be a way to remedy this within matplotlib, but it looks like you've already explored the options there. If you can provide a minimal example (of just rendering some text in matplotlib using ax.annotate) with a garbled case, and some matplotlib that makes it "correct" I can possibly try to get fixes integrated into datamapplot, but if you don't know how to make matplotlib do the right thing then I don't think there is much I can do.

@NullPxl
Copy link

NullPxl commented Dec 6, 2024

Hey @superseanyoung , I was having the same issue when my data contained many types of scripts. Here's how I solved it:

font_filepaths = [
    "/home/user/scratch/fonts/Noto_Sans/NotoSans-VariableFont_wdth,wght.ttf",
    "/home/user/scratch/fonts/Noto_Sans_Arabic/NotoSansArabic-VariableFont_wdth,wght.ttf",
    "/home/user/scratch/fonts/Noto_Sans_JP/NotoSansJP-VariableFont_wght.ttf",
    "/home/user/scratch/fonts/Noto_Sans_KR/NotoSansKR-VariableFont_wght.ttf",
    "/home/user/scratch/fonts/Noto_Sans_SC/NotoSansSC-VariableFont_wght.ttf",
    "/home/user/scratch/fonts/Noto_Sans_TC/NotoSansTC-VariableFont_wght.ttf"
]

font_families = [] # order of fallback
for font_path in font_filepaths:
    font = fm.FontProperties(fname=font_path)
    font_families.append(font.get_name())
    fm.fontManager.addfont(font_path)
    
fig,ax = datamapplot.create_plot(reduced_embeddings, custom_names,  font_family=font_families)

Hope this helps!

@DalelanW
Copy link

DalelanW commented Jan 23, 2025

I believe to have found the easier fix to this. It seems specifying the font name explicitly worked

fig,ax = datamapplot.create_plot( reduced_embeddings, custom_names, font_family="Noto Sans JP")

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