Matplotlib:编写从右到左的文本(希伯来语,阿拉伯语等) [英] Matplotlib: Writing right-to-left text (Hebrew, Arabic, etc.)

查看:66
本文介绍了Matplotlib:编写从右到左的文本(希伯来语,阿拉伯语等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向我的图添加一些文本,即 RTL(在本例中为希伯来语).经过一些工作后,设法使它显示文本,但显示了LTR(意思是按照reverese顺序排列).我已经深入研究了参考资料并在网上进行了大量搜索,但没有任何结果.

I'm trying to add some text to my plot which is RTL (in this case, Hebrew). After some work managed to get it to display the text, but it's displayed LTR (meaning, in the reverese order). I've dug into the reference and did extensive search online and nothing came up.

我正在使用的示例:

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

,并显示אהתיכםלוש".如果您看不到希伯来语,就好像我输入了Hello",输出将是olleH".

and it displays 'א התיכ םלוש'. In case you can't see the Hebrew, it's as if i'd input 'Hello', and the output would be 'olleH'.

由于输入是LTR和RTL的混合,所以我不能简单地撤消输入.

I can't simply reverse the input since it's mixed LTR and RTL.

我们将不胜感激.

推荐答案

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

For whoever encounters the same problem, I found a partial solution.

bidi软件包提供了此功能,因此可以使用:

The bidi package provides this functionality, so using:

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一起使用的乳胶表达.所以请谨慎使用.

So why is it partial? Because I found out that the bidi package sometimes messes up latex expression which I use with matplotlib. So use it carefully.

这篇关于Matplotlib:编写从右到左的文本(希伯来语,阿拉伯语等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆