%pylab inline
import matplotlib.pyplot as plt
import numpy as np
from scipy.special import gamma
from scipy.misc import factorial
Populating the interactive namespace from numpy and matplotlib
Use the scipy versions instead of the math package versions so they can be applied directly to ndarrays
# The x values to plot
# Factorial is only defined for non-negative integers
x_fact = np.arange(0,6,1)
x_gamma = np.linspace(0,5,100)
plt.plot(x_gamma, gamma(x_gamma), linewidth=3, label='gamma(x)');
plt.plot(x_fact, factorial(x_fact,exact=True), '.', markersize=15, color='grey', markeredgecolor='black', label='factorial(x)');
legend();
title('gamma(x) and factorial(x)');
plt.plot(x_gamma, gamma(x_gamma+1), linewidth=3, label='gamma(x+1)');
plt.plot(x_fact, factorial(x_fact,exact=True), '.', markersize=15, color='grey', markeredgecolor='black', label='factorial(x)');
legend();
title('gamma(x+1) and factorial(x)');