Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPython Notebook: Plotting with LaTeX?

Displaying lines of LaTeX in IPython Notebook has been answered previously, but how do you, for example, label the axis of a plot with a LaTeX string when plotting in IPython Notebook?

like image 293
user1988816 Avatar asked Sep 12 '26 22:09

user1988816


1 Answers

It works the same in IPython as it does in a stand-alone script. This example comes from the docs:

import matplotlib as mpl
import matplotlib.pyplot as plt
mpl.rc('text', usetex = True)
mpl.rc('font', family = 'serif')
plt.figure(1, figsize = (6, 4))
ax = plt.axes([0.1, 0.1, 0.8, 0.7])
t = np.arange(0.0, 1.0+0.01, 0.01)
s = cos(2*2*pi*t)+2
plt.plot(t, s)

plt.xlabel(r'\textbf{time (s)}')
plt.ylabel(r'\textit{voltage (mV)}', fontsize = 16)
plt.title(r"\TeX\ is Number $\displaystyle\sum_{n=1}^\infty\frac{-e^{i\pi}}{2^n}$!",
      fontsize = 16, color = 'r')
plt.grid(True)
plt.savefig('tex_demo')
plt.show()

enter image description here

like image 80
unutbu Avatar answered Sep 14 '26 12:09

unutbu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!