Matplotlib:从右到左书写(希伯来语,阿拉伯语等)

时间:2013-03-14 22:54:21

标签: python matplotlib hebrew right-to-left

我正在尝试在我的情节中添加一些文本,即RTL(在本例中为希伯来语)。经过一些工作设法让它显示文本,但它显示LTR(意思是,以崇敬的顺序)。我已经挖掘了参考资料并在网上进行了广泛的搜索,没有任何结果。

我正在使用的一个例子:

import matplotlib.pyplot as plt
plt.text(0.5, 0.5, u'שלום כיתה א', name = 'Arial')
plt.show()

它显示'אהתיכםלוש'。 如果你看不到希伯来语,就好像我输入'Hello',输出就是'olleH'。

我不能简单地反转输入,因为它是混合LTR和RTL。

我们将不胜感激。

6 个答案:

答案 0 :(得分:19)

对于阿拉伯语,您需要bidi.algorithm.get_displayarabic_reshaper个模块:

from bidi.algorithm import get_display
import matplotlib.pyplot as plt
import arabic_reshaper

reshaped_text = arabic_reshaper.reshape(u'لغةٌ عربيّة')
artext = get_display(reshaped_text)

plt.text(0.25, 0.45, artext , name = 'Times New Roman',fontsize=50)
plt.show()

python matplotlib arabic text

答案 1 :(得分:15)

对于遇到同样问题的人,我找到了部分解决方案。

bidi package提供此功能,因此使用:

from bidi import algorithm as bidialg
import matplotlib.pyplot as plt
text = bidialg.get_display(u'שלום כיתה א')
plt.text(0.5, 0.5, text , name = 'Arial')
plt.show()

正确显示。

那么为什么它偏袒? 因为我发现bidi包装有时会混淆我使用matplotlib的乳胶表达。所以要小心使用它。

答案 2 :(得分:0)

我遇到了同样的问题,我认为同时使用@Korem和@Nasser Al-Wohaibi的答案,就像这样:

SumR: IIf([Forms]![FrmDSTResultsCompare]![Test1] And [Test1] = S,"1","0")

因为只有arabic_reshaper并没有重新排列字母,而比迪烟也没有将它们组合在一起

^ _ ^

答案 3 :(得分:0)

改用altair。它立即与阿拉伯语/波斯语文字兼容。无需更改任何内容! https://altair-viz.github.io/index.html

答案 4 :(得分:0)

我知道我的答案不是解决此问题的方法,但是使用Plotly而不是matplotlib解决了我的问题。它会正确显示波斯语单词。

答案 5 :(得分:-2)

您可以尝试通过以下方式翻转文本:

    Utils.execute(DomainClass.class, DomainClass::dummyMethod);

相关问题