【问题标题】:Mixed multiple persian(farsi) and english text in matplotlib? [duplicate]在matplotlib中混合多个波斯语(波斯语)和英文文本? [复制]
【发布时间】:2020-03-17 15:55:36
【问题描述】:

我想在 matplotlib 中使用波斯字体,但是当像 فایل pdf 那样混合文本时,英文文本会显示为一些正方形。我的代码如下:

import seaborn as sns; sns.set()
import matplotlib.pyplot as plt
from bidi.algorithm import get_display
import arabic_reshaper

from matplotlib import font_manager as fm, rcParams
import os

fpath = os.path.join(rcParams["datapath"],"C:\\Users\\Ahmad\\Desktop\\Report_Examples\\BNazanin.ttf")

prop = fm.FontProperties(fname=fpath)



def make_farsi_text(x):
    reshaped_text = arabic_reshaper.reshape(x)
    farsi_text = get_display(reshaped_text)
    return farsi_text

fmri = sns.load_dataset("fmri")
ax = sns.lineplot(x="timepoint", y="signal", data=fmri)
ax.set_xlabel(make_farsi_text('فایل pdf'),fontproperties=prop)
plt.show()

【问题讨论】:

  • 问题是字体文件BNasanin.ttf不支持英文字符-大概是因为它是纯波斯语字体文件。解决方案是使用两种不同的字体文件或同时支持波斯语和英文字符的单个文件。在 Matplotlib 文本实例中混合字体可能只能使用 LaTex,我不确定

标签: python matplotlib


【解决方案1】:

我使用了另一种字体,我的问题解决了。我使用 XB Niloofar 字体。您可以从以下链接下载它:

XB Niloofar download link

【讨论】:

    猜你喜欢
    • 2021-12-15
    • 1970-01-01
    • 1970-01-01
    • 2019-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-28
    相关资源
    最近更新 更多