Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python matplotlib中的阿拉伯文文本_Python_Python 3.x_Matplotlib_Arabic Support - Fatal编程技术网

Python matplotlib中的阿拉伯文文本

Python matplotlib中的阿拉伯文文本,python,python-3.x,matplotlib,arabic-support,Python,Python 3.x,Matplotlib,Arabic Support,xlabel和ylabel不显示阿拉伯语 x = [2, 4, 6, 8, 10] y = [6, 7, 8, 9, 10] plt.bar(x, y, label='Bar1', color='red') plt.xlabel("الفواصل") plt.ylabel("الترتيبات") plt.show() 如果您使用unicode字符串(u“الفوال”)而不是通常的字符串,它应该可以工作 x = [2, 4, 6, 8, 10] y = [6, 7, 8, 9, 10]

xlabel和ylabel不显示阿拉伯语

x = [2, 4, 6, 8, 10]
y = [6, 7, 8, 9, 10]

plt.bar(x, y, label='Bar1', color='red')
plt.xlabel("الفواصل")
plt.ylabel("الترتيبات")
plt.show()

如果您使用unicode字符串(
u“الفوال”
)而不是通常的字符串,它应该可以工作

x = [2, 4, 6, 8, 10]
y = [6, 7, 8, 9, 10]

plt.bar(x, y, label='Bar1', color='red')
plt.xlabel(u"الفواصل")
plt.ylabel(u"الترتيبات")
plt.show()

或者,为了得到正确的顺序

import matplotlib.pyplot as plt
x = [2, 4, 6, 8, 10]
y = [6, 7, 8, 9, 10]

plt.bar(x, y, label='Bar1', color='red')
plt.xlabel(u"الفواصل"[::-1])
plt.ylabel(u"الترتيبات"[::-1])
plt.show()

您首先需要安装和

阿拉伯文情节


如果字体没有阿拉伯字形,您将看不到阿拉伯语。但是,如果将Unicode文本编码为UTF-8字节,会发生什么?例如
“الوال”。encode()
您使用哪种Python版本?如果仍在使用Python2.7,请升级到Python3。Python2.7中的Unicode/UTF-8处理有点破绽。“افول”。encode()不起作用我使用Python3,“㶇ول”。encode(“ascii”,“忽略”)不起作用work@kay这与Python2或Python3无关。我仍然有相同的问题。在这种情况下,您可能需要更新matplotlib。这可能是因为您的版本太旧,并且使用的字体没有所有可用的unicode符号。是的,如果字体实际具有这些阿拉伯字形,它应该可以工作。而
u
前缀仅在Python2中需要,在Python3中所有正常的文本字符串都是Unicode对象,因此不需要
u
前缀(尽管最近的Python3版本出于Python2兼容性的原因允许使用)。顺便说一句,这仍然存在一个大问题:字母顺序错误(从左到右)而且不相交。我不知道如何连接字母。但您可以反转字符串以获得正确的顺序。
import arabic_reshaper
from bidi.algorithm import get_display
import matplotlib.pyplot as plt
x = [2, 4, 6, 8, 10]
y = [6, 7, 8, 9, 10]
xlbl = get_display( arabic_reshaper.reshape('الفواصل'.decode('utf8')))
ylbl = get_display( arabic_reshaper.reshape('الترتيبات'.decode('utf8')))
plt.bar(x, y, label='Bar1', color='red')
plt.xlabel(xlbl, fontdict=None, labelpad=None)
plt.ylabel(ylbl, fontdict=None, labelpad=None)
plt.show()