how to put non-latin text on plots?

Hi Everyone,
Not really related to my every day work, but I was asking myself how to put non latin letters, like arabic or hebrew on plots.

I found a way to put german umlauts and ß but this is only a very partial solution. It would be cool to know how to over come this.

My code to work with umlauts is:

#!/usr/bin/env python

-- coding: utf-8 --

import matplotlib.pyplot as plt
import numpy as np

def format(x, pos=None):
if x == 0.0:
exp = 0

else:
exp = int(np.log10(np.abs(x)))
mant = x / 10**exp
return ‘%.1fE%+d’ % (mant, exp)

f = plt.figure()
ax = f.add_subplot(111)
data = np.array([1,2,3,4,5]) / 100.
ax.plot(data, np.arange(len(data)))

ax.xaxis.set_major_formatter(plt.FuncFormatter(format))
ax.yaxis.set_major_formatter(plt.FuncFormatter(format))
ax.text(0.03,0.5,“Umlauts äüöß”+ u"\u00e4")
plt.show()

If I include arabic or hebrew letters I get Bricks displays.

Thanks in advance,

Oz

···


Oz Nahum
Graduate Student
Zentrum für Angewandte Geologie
Universität Tübingen


Imagine there’s no countries
it isn’t hard to do

Nothing to kill or die for
And no religion too
Imagine all the people
Living life in peace

You may need to use a font with a more complete character set, such as
DejaVu.

Mike

···

http://p.sf.net/sfu/nokia-dev2dev


Matplotlib-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/matplotlib-users

-- Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA

I should also add that matplotlib doesn’t have any advanced text layout
algorithms (such as what would be found in Pango), so Hebrew and Arabic
are likely to be backwards and wrong.

Mike

···

http://p.sf.net/sfu/nokia-dev2dev


Matplotlib-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/matplotlib-users

-- Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA

http://p.sf.net/sfu/nokia-dev2dev


Matplotlib-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/matplotlib-users

-- Michael Droettboom
Science Software Branch
Space Telescope Science Institute
Baltimore, Maryland, USA