Visualization 1: Matplotlib Basics Exercises


In [57]:
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

Scatter plots

Learn how to use Matplotlib's plt.scatter function to make a 2d scatter plot.

  • Generate random data using np.random.randn.
  • Style the markers (color, size, shape, alpha) appropriately.
  • Include an x and y label and title.

In [58]:
plt.figure(figsize=(10,8))
plt.scatter(np.random.randn(100),np.random.randn(100),s=50,c='b',marker='d',alpha=.7)
plt.xlabel('x-coordinate')
plt.ylabel('y-coordinate')
plt.title('100 Random Points')


Out[58]:
<matplotlib.text.Text at 0x7f9582328c10>

Histogram

Learn how to use Matplotlib's plt.hist function to make a 1d histogram.

  • Generate randpom data using np.random.randn.
  • Figure out how to set the number of histogram bins and other style options.
  • Include an x and y label and title.

In [59]:
plt.figure(figsize=(10,8))
p=plt.hist(np.random.randn(100000),bins=50,color='g')
plt.xlabel('value')
plt.ylabel('frequency')
plt.title('Distrobution 100000 Random Points with mean of 0 and variance of 1')


Out[59]:
<matplotlib.text.Text at 0x7f958213d710>