El Sábado, 18 de enero de 2014 17:09:30 Mauricio Calvao escribió:
> Hi
> 
> I would like to know whether it is possible to save a simple (or complex,
> for that matter) figure in 2 files, such that one of them contains, for
> instance, the lines or points or surfaces ("graphics") typically in pdf
> format and the other contains the whole text of the figure (labels,
> numbers, title, annotations, etc). This is achievable in gnuplot via its
> epslatex terminal and is highly convenient, in the sense that the fonts of
> the figure match exactly the fonts (size, family, etc) of the main text in
> which it will be embedded; even if we resize the figure, the corresponding
> text, in perfect beautiful Latex, will match the surrounding main body text
> of the master document. This is also possible with Inkscape and its
> PDF+Latex saving option.
> 
> Is this possible with matplotlib or are there any workarounds?

If you only want to get a figure where the rendering of the text is done with 
latex, you can use savefig in pgf format.  As an example:

  Contents of matplotlibrc:

  [...]
  backend      : Qt4Agg
  pgf.rcfonts : False
  pgf.texsystem : pdflatex
  pgf.preamble  \usepackage{path_to_your_document/foo}
  [...]

  Script to create the figure:

  #!/usr/bin/env python

  import matplotlib.pyplot as plt
  import numpy as np

  x = np.linspace(0, 4. * np.pi)
  y = np.sin(x) ** 2

  fig = plt.figure(figsize=(3, 3))
  ax = plt.gca()
  ax.plot(x, y)
  ax.set_xlabel(r'$x$')
  ax.set_ylabel(r'$\sin \left( x \right) ^ 2$')
  plt.savefig('path_to_your_document/foo.pgf')

  Main document:

  \documentclass{article}

  \usepackage{foo}

  \begin{document}

    \begin{figure}[H]
      \input{foo.pgf}
    \end{figure}

  \end{document}

  Style file (foo.sty):
  
  \usepackage{amsmath}
  \usepackage{float}
  \usepackage{fouriernc}
  \usepackage{graphicx}
  \usepackage{pgf}

The main problem with this, is that you can not resize the figure (i.e., with 
a resizebox) without also resizing the text. If you want to get the figure 
with a bigger or smaller size, you have to regenerate the file changing its 
figsize. The benefit of this method is that all the drawing is made by latex, 
so you have perfectly matched fonts, colors...

-- 
Luis Miguel García-Cuevas González

Attachment: signature.asc
Description: This is a digitally signed message part.

------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to