Hi all,
I have been trying to follow your tips regarding matplotlib and arabic support.
Indeed matplotlib with Latex and unicode work great together :
#-*- coding: utf-8 -*-
from pylab import *
from matplotlib import rcParams
rcParams['text.usetex']=True
rcParams['text.latex.unicode']=True
figure(1)
plot([1,2,3])
title(unicode(r'\textit{éèê}','utf8'))
show()
But then I came to the conclusion that Latex did not support Arabic.
This few lines generate a "missing def" error.
\documentclass{article}
\usepackage{ucs}
\usepackage[utf8x]{inputenc}
\title{éèê هه}
\begin{document}
\maketitle
\end{document}
Is it related to my installation ? (Ubuntu with package
texlive-latex-recommended)
I asked here : Latex Unicode : missing .def for arabic ?
Somebody pointed me out XeTeX, which has wider support for Unicode.
www.tug.org/TUGboat/Articles/tb27-2/tb87kew.pdf
I was wondering if there could be a way to get matplotlib work with XeTeX.
What do you think ? Is it the right track ? Should I switch to
grandpa's gnuplot ?
Thank you all,
Mathieu.
Michael Droettboom wrote:
···
Unfortunately, I believe this is a fundamental incompatibility within
matplotlib. matplotlib uses a very simple algorithm for layout out a
line of characters which assumes ltr order and all kinds of other things.That said, there is something you could try. Matplotlib has a "usetex"
mode which will do all text rendering using LaTeX. Assuming you can get
LaTeX to handle Arabic correctly, you can set the following in your
.matplotlibrc file:text.usetex : True
text.latex.unicode : TrueYou'll need to install the LaTeX Unicode extension "ucs" (Ubuntu
probably has packages for that.) If you need to load any LaTeX packages
to get arabic support, you can tell matplotlib about them in your
matplotlibrc like so:text.latex.preamble: \usepackage{foo}
If Arabic-encoded-as-Unicode doesn't work, you could try setting
"text.latex.unicode" to False, and then typing your Arabic strings using
one of the other Arabic encodings that LaTeX understands.Please let us know if you have success or hit another roadblock.
Cheers,
MikeBurhan Khalid wrote:
Hello All:
Having an issue with Arabic font support using matplotlib. When using
the correct font, Arabic characters are displayed, but are not joined
together
properly; and they are also not in the correct order (the font rendered is
ltr, but Arabic is a rtl language). Is this an issue with the render I
am using, or some incompatibility within matplotlib? Sample source code
used (please note, your email client should support utf8 to display the
code correctly).#-*- coding: utf-8 -*-
from pylab import *
figure(1) # the first figure
plot([1,2,3])
figure(1) # figure 1 current
title(u'برهان',name='Times New Roman') # figure 1 title
savefig('test.png')
savefig('test.eps')
show()Output when run from the command line:
matplotlib data path /usr/share/matplotlib/mpl-data
$HOME=/home/burhan
CONFIGDIR=/home/burhan/.matplotlib
loaded rc file /etc/matplotlibrc
matplotlib version 0.90.1
verbose.level helpful
interactive is False
units is True
platform is linux2
numerix numpy 1.0.3
font search path ['/usr/share/matplotlib/mpl-data/fonts/ttf',
'/usr/share/matplotlib/mpl-data/fonts/afm']
loaded ttfcache file /home/burhan/.matplotlib/ttffont.cache
backend TkAgg version 8.4
Could not match Bitstream Vera Serif, New Century Schoolbook, Century
Schoolbook L, Utopia, ITC Bookman, Bookman, Nimbus Roman No9 L, Times
New Roman, Times, Palatino, Charter, serif, normal, normal. Returning
/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttfThis is on a clean Ubuntu Gutsy install, using python 2.5.1.
Thanks,
Burhan------------------------------------------------------------------------
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/------------------------------------------------------------------------
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options