Andreas Hilboll wrote:
> 
>> I wrote a new backend that uses the "pgf" latex package for drawing
>> matplotlib figures. It is compatible with pdflatex, xelatex and lualatex.
>> The pgf pictures can be included in latex documents or can be directly
>> compiled to PDF by the backend, utilizing the benefits of Xelatex.
>>
>> The code for the backend and a script creating a test figure is on
>> github:
>> https://github.com/pwuertz/matplotlib-backend-pgf/
> 
> Looks great! How do I use this with my currently installed matplotlib
> 1.1.0?
> 

The easiest way without touching your matplotlib installation is to fetch
"backend_pgf.py" from github and put it in the directory where you are
running your plotting script (or in any directory in python's search path).
Then have a look at "test_pgf_backend.py". It demonstrates how to select and
configure the pgf backend. Basically, you just call

matplotlib.use('module://backend_pgf')

to use it. With the backend selected, the show() command won't work anymore
since this is not a GUI backend, but you can now save the figure as ".pgf"
file (just the pgf commands for latex) or ".pdf" file (already compiled with
xelatex). Also make sure that you select a font that exists on your system

matplotlib.rcParams.update({"pgf.font": "CMU Serif"})

or you'll get an exception when saving the figure. As already said, you'll
get the best results when you install the Computer Modern Unicode Fonts
(Ubuntu Package: fonts-cmu, Manual Install:
http://sourceforge.net/projects/cm-unicode/). Be aware that if there is any
text element that produces an error in Latex the savefig call will stall
until I have found a better way to deal with such errors.


Incorporating the backend into matplotlib requires a little more work. You
have to copy the file to the folder where all the other modules reside (for
me it's /usr/lib/pymodules/python2.7/matplotlib/backends/) and then include
the "pgf" type in "backend_bases.py" one folder above. I'm not sure how to
handle the case when the user wants to create a pdf from backend_pgf instead
of backend_pdf since the only 'switch' is the extension of the file. But I'd
suggest to use the matplotlib.use method for now..

Good luck ;)
-- 
View this message in context: 
http://old.nabble.com/Pgf-Backend-with-Xelatex-support-tp34072290p34082447.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to