Customizing PyLab using style

We will start by importing numpy, matplotlib, and pyplot, as follows:

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

We will also import matplotlib and also import a couple of extra lines to make our plots show up in a proper format:

%matplotlib inline
# Set up figure size and DPI for screen demo
plt.rcParams['figure.figsize'] = (6,4)
plt.rcParams['figure.dpi'] = 150

from scipy.ndimage.filters import gaussian_filter
plt.subplot(221)
plt.text(0.5, 0.5, 'hello')
plt.plot(np.arange(0,1,0.01), np.power(np.arange(0,1,0.01), 3))
plt.ylabel('Axis Label')
plt.subplot(222)
plt.scatter(np.random.normal(size=10), np.random.normal(size=10), c=np.random.normal(size=10))
plt.subplot(223)
plt.hist(np.random.normal(size=1000));
plt.hist(np.random.normal(1, size=1000));
plt.hist(np.random.normal(2, size=500));
plt.ylabel('Axis Label')
plt.xlabel('Axis Label')
plt.subplot(224)
plt.imshow(gaussian_filter(np.random.normal(size=(200,300)), sigma=10))
plt.xlabel('Axis Label')

We will begin with the preceding big block of code and will make an array—a little grid of four plots showing four basic plot types which includes a line plot (top left), a scatter plot (top right), a histogram (bottom left), and an image plot (bottom right), along with the respective axis labels:

By default, Matplotlib will choose some fairly sensible choices for things like fonts, colors, and the other appearance attributes of these plots. These defaults aren't the only choices for appearance attributes that Matplotlib provides.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset