Feeds:
Posts

## Using Python for Plotting Functions

As I wrote last week I think, I’m teaching Modern Physics at the Catholic University of Valparaiso.

Since I’m a LaTeX lover and a prolific writer (just science b.t.w.), just decide to prepare some lecture notes of the course (in Spanish) for my students… and for producing the pictures I’m using the matplotlib module of Python.

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0.,5.,0.001)
y = 1.0/np.sqrt(1- x**2)

plt.plot(x, x**2/2.0, ‘r–‘, x, x**3/(np.exp(2*x)-1), ‘b’)
plt.axis([0,5,0,0.4])
plt.ylabel(r’$\mathcal{R}(\nu)$’, fontsize = 15)
plt.xlabel(r’Frecuencia $\nu$’, fontsize = 15)

plt.annotate(‘Teoria Clasica’, xy=(1, 0.35), xytext=(1.6, 0.35), \ arrowprops = dict(facecolor = ‘red’, shrink=0.1))
plt.annotate(‘Experimento’, xy=(2, 0.15), xytext=(2.4, 0.25),\ arrowprops = dict(facecolor = ‘blue’, shrink=0.1))

plt.show()

BB-varius

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(0.,15.,0.001)

plt.plot(x, x**3/(np.exp(2*x)-1), ‘r’, x, x**3/(np.exp(x)-1), ‘b’, x,\ x**3/(np.exp(2*x/3.0)-1), ‘g’)
plt.axis([0,15,0,5])
plt.ylabel(r’$\mathcal{R}(\nu)$’, fontsize = 15)
plt.xlabel(r’Frecuencia $\nu$’, fontsize = 15)

plt.annotate(“”, xy=(1.41396, 0.17766), xytext=(1.41396, 0.),\ arrowprops=dict(arrowstyle=”-“, connectionstyle=”arc3”))
plt.annotate(“”, xy=(2.82534, 1.42151), xytext=(2.82534, 0.),\ arrowprops=dict(arrowstyle=”-“, connectionstyle=”arc3”))
plt.annotate(“”, xy=(4.23398, 4.79732), xytext=(4.23398, 0.),\ arrowprops=dict(arrowstyle=”-“, connectionstyle=”arc3”))

plt.annotate(r’$T$’, xy=(2, 0.15), xytext=(2.4, 0.65),\ arrowprops=dict(facecolor = ‘red’, shrink=0.1))
plt.annotate(r’$2T$’, xy=(4, 1.45), xytext=(5, 2.),\ arrowprops=dict(facecolor = ‘blue’, shrink=0.1))
plt.annotate(r’$3T$’, xy=(7.24, 4.15), xytext=(8.5, 4.5),\ arrowprops = dict(facecolor = ‘green’, shrink=0.1))

plt.show()

Those are the final pictures I include in the notes, which are updated at least once a week at the google group page.