Skip to content
Ramesh Sridharan edited this page Mar 10, 2014 · 3 revisions

Here are some examples of plots you can make with beauty. While these examples produce output in PNG format, you can easily make vectorized versions using PDF just by changing the file extensions.

Anscombe's Quartet

A visualization of Anscombe's Quartet.

Code

import beauty
import numpy as np
import matplotlib.pyplot as plt

# Data from http://matplotlib.org/examples/pylab_examples/anscombe.html
x = np.empty([4,11])
y = np.empty([4,11])
x[0,:] = x[1,:] = x[2,:] =  np.array([10,8,13,9,11,14,6,4,12,7,5])
y[0,:] = np.array([8.04,6.95,7.58,8.81,8.33,9.96,7.24,4.26,10.84,4.82,5.68])
y[1,:] = np.array([9.14,8.14,8.74,8.77,9.26,8.10,6.13,3.10,9.13,7.26,4.74])
y[2,:] = np.array([7.46,6.77,12.74,7.11,7.81,8.84,6.08,5.39,8.15,6.42,5.73])
x[3,:] = np.array([8,8,8,8,8,8,8,19,8,8,8])
y[3,:] = np.array([6.58,5.76,7.71,8.84,8.47,7.04,5.25,12.50,5.56,7.91,6.89])

plt.figure(figsize=(3,3))
for i in xrange(4):
    plt.subplot(2,2,i+1)
    beauty.scatter(x[i], y[i])
    plt.axis([0,20,0,14])
    
    # Plot regression line
    xl = np.array([0,20])
    plt.plot(xl, 3+0.5*xl, color=beauty.green)
plt.tight_layout()
plt.savefig('anscombe.png')

Data histogram with distribution

Histogram of data generated from a Gaussian distribution (blue), along with the distribution itself (green). Requires LaTeX.

Code

import beauty
import numpy as np
import matplotlib.pyplot as plt

data = np.random.normal(0,1, 1000)
x = np.linspace(-4,4, 100)
f = 1/np.sqrt(2*np.pi) * np.exp(-x**2 / 2)
gaussian_dist = r'$\frac{1}{\sqrt{2\pi}}e^{-\frac{1}{2}x^2}$'

plt.figure(figsize=(4, 2))
plt.hist(data, bins=20, normed=True, label='Data')
plt.plot(x, f, color=beauty.green, label=gaussian_dist, linewidth=2.0)
plt.legend()
plt.savefig('histogram.png')
Clone this wiki locally