r4ds-python-plotnine icon indicating copy to clipboard operation
r4ds-python-plotnine copied to clipboard

TeX Improvements

Open has2k1 opened this issue 4 years ago • 0 comments

Thank you for creating this extensive tutorial. A few improvements on using TeX:

  1. All you need to do is wrap the text with $.
  2. You can avoid the double escaping by using raw strings i.e r'string'.

So this chunk

from matplotlib import rc
rc('text', usetex=True)

df = pd.DataFrame({"x": np.random.uniform(size=10),
                   "y": np.random.uniform(size=10)})

ggplot(df, aes("x", "y")) +\
geom_point() +\
labs(x="$\\sum_{i = 1}^n{x_i^2}$",
     y="$\\alpha + \\beta + \\frac{\\delta}{\\theta}$")

becomes this

df = pd.DataFrame({"x": np.random.uniform(size=10),
                   "y": np.random.uniform(size=10)})

ggplot(df, aes("x", "y")) +\
geom_point() +\
labs(x=r"$\sum_{i = 1}^n{x_i^2}$",
     y=r"$\alpha + \beta + \frac{\delta}{\theta}$")

has2k1 avatar Sep 06 '20 13:09 has2k1