Re: [Matplotlib-users] Pgf Backend with Xelatex support
> > Hi, > > When creating figures to be included in Latex documents I encountered a > few > problems. In the end the text rendering just doesn't blend in well, one > way > or another. I found that the problems can be fixed by using Xelatex, which > provides full unicode support and is able to use the installed fonts of > your > operating system. > > 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/ > > A document that demonstrates the benefits of using pgf/xelatex is also > there: > https://github.com/pwuertz/matplotlib-backend-pgf/raw/master/demo/demo.pdf > > Although I think the pgf backend is very useful already and produces > figures > in publication quality (an overused expression ;) ), there are still some > loose ends. Basically, everything I need works but I don't have the time > anymore to figure out all the rest. Maybe someone is interested in > improving > this backend, possibly making it a real option for the masses? I wrote > down > all open questions I had in TODO comments within the code. To summarize > them: > > * The default font for the backend is the unicode variant of Computer > Modern > (CMU Serif), which might not be present on most users' systems. If you > don't > want to install/use it, you can just specify another (see test script). I > could as well check for the fonts specified in the rc parameters but these > just do fit in Latex documents. > > * When printing pgf commands, the actual font depends on the latex > environment you are embedding the figure in. Matplotlib only needs a font > for calculating the text positions and for direct PDF output. > > * I'm not sure how certain draw methods of the renderer should behave due > to > lack of documentation. > > * Some text properties like switching font families or making the text > italic/bold are ignored since I did not need them. > > * Backends like svg or pdf are able to display the document upon show(). I > don't know how this is achieved without creating a graphical user > interface > myself. The other backends don't implement it. > > * The method of obtaining the metrics of text elements is pretty cool I > think (XelatexManager), but it breaks easily since there is no way of > defining a timeout for reading the output of a subprocesses that keeps > running during the figure creation process. Right now, if Latex doesn't > understand a text-element the process stalls. An alternative is to run a > new > latex process for every single text element or start using threads. > Looks great! How do I use this with my currently installed matplotlib 1.1.0? Cheers, A. -- 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
Re: [Matplotlib-users] Pgf Backend with Xelatex support
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
[Matplotlib-users] Plot line/Line2D with edgecolor
Hello, I would like to plot a simple line using plt.plot(x, y, ‘w--’, lw=2) or with the corresponding axes instance ax.plot(x, y, ‘w--’, lw=2). However, I want the line to have a thin black edge like the edge of a marker. Is this possible? I tried to find a property of the Line2D object but I could not find anything. Has someone an idea? Thanks in advance Daniel -- 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
Re: [Matplotlib-users] Plot line/Line2D with edgecolor
On Wed, Jun 27, 2012 at 5:02 PM, Daniel Platz wrote: > Hello, > > I would like to plot a simple line using plt.plot(x, y, ‘w--’, lw=2) > or with the corresponding axes instance ax.plot(x, y, ‘w--’, lw=2). > However, I want the line to have a thin black edge like the edge of a > marker. Is this possible? I tried to find a property of the Line2D > object but I could not find anything. Has someone an idea? Daniel, Here's how civil-engineer-hack-fest that i'd use to do it: import matplotlib.pyplot as plt import numpy as np x = np.arange(0,10,0.1) y = -4 + 2*x - 1.5*x**2 fig, ax1 = plt.subplots() ax1.plot(x, y, 'c-', lw=2.5, zorder=10) ax1.plot(x, y, 'k-', lw=4.0, zorder=5) plt.show() Hope that helps. -paul -- 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