Monthly Archives: noviembre 2014

You are browsing the site archives by month.

figures from ggplot2 to pictex

The ggplot2 R package recognises the tex extension and it allows to export the data graphics to latex documents. The tex output doesn’t look like the original file but with a little code editing we can get a quite good figure. Here is an example of the original and the exported line graphic once retouched.


disp <− qplot(date, unemploy / pop, data = economics, geom = "line")
disp + theme(panel.grid.major = element_line(colour = "white"), panel.border = element_rect(colour = NA))
ggsave(filename = "graf_lin.tex", scale=2, width = 10, height = 5, units = "cm", dpi = 300)


stargazer R package to create LaTeX code

stargazer is an R package that can help you create LATEX code for summary statistics tables, data frames, vectors and matrices. Once stargazer package is installed and activated it is really easy to use! Here is an example:


stargazer(diamonds,title="Summary−DVFMTSC−> statistics−DVFMTSC−> of−DVFMTSC−> 'diamonds'−DVFMTSC−> data−DVFMTSC−> frame",align=TRUE)

text rendering with LaTeX in matplotlib

Matplotlib has the option to use LaTeX to manage all text layout.

The LaTeX option is activated by setting “text.usetex: True” in the rc settings. Text handling with matplotlib’s LaTeX support is slower than matplotlib’s very capable mathtext, but is more flexible, since different LaTeX packages (font packages, math packages, etc.) can be used.


The code of this figure is as simple as:

import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt

mpl.rcParams['legend.fontsize'] = 14
plt.rc('text', usetex=True)
plt.rc('font', family='serif')

fig = plt.figure()
ax = fig.gca(projection='3d')
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
z = np.linspace(-4, 4, 100)
r = z**2 + 1
x = r * np.sin(theta)
y = r * np.cos(theta)
ax.plot(x, y, z, label='$Parametric$ $curve$', alpha=0.8)
ax.legend(numpoints=1, loc=1, frameon=False)

more than 150 TeX formatted books ready to download

It is a nice to compare the code of more than 150 TeX books that anyone can download from Gutenberg Project. You just have to look for TeX files at I don’t understand why this advanced search page is deprecated.