[Matplotlib-users] how to put non-latin text on plots?

2010-09-23 Thread Oz Nahum
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
--
Nokia and ATT present the 2010 Calling All Innovators-North America contest
Create new apps  games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] how to put non-latin text on plots?

2010-09-23 Thread Michael Droettboom
You may need to use a font with a more complete character set, such as 
DejaVu.


Mike

On 09/23/2010 02:56 PM, Oz Nahum wrote:

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



--
Nokia and ATT present the 2010 Calling All Innovators-North America contest
Create new apps  games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev


___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
   



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

--
Nokia and ATT present the 2010 Calling All Innovators-North America contest
Create new apps  games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] how to put non-latin text on plots?

2010-09-23 Thread Michael Droettboom
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

On 09/23/2010 03:07 PM, Michael Droettboom wrote:
You may need to use a font with a more complete character set, such as 
DejaVu.


Mike

On 09/23/2010 02:56 PM, Oz Nahum wrote:

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



--
Nokia and ATT present the 2010 Calling All Innovators-North America contest
Create new apps  games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev


___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
   



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


--
Nokia and ATT present the 2010 Calling All Innovators-North America contest
Create new apps  games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev


___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
   



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

--
Nokia and ATT present the 2010 Calling All Innovators-North America contest
Create new apps  games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users