Visualization 1: Matplotlib Basics Exercises


In [2]:
%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 [13]:
a= 10
x = np.random.rand(a)
y = np.random.rand(a)
colors = np.random.rand(a)
area = np.pi * (12 * np.random.rand(a))**2
plt.scatter(x, y, s=area, c=colors, alpha=0.5)
plt.xlabel('x')
plt.ylabel('y')
plt.title('Dots Are Fun')
plt.show()


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 [15]:
np.random.randn
plt.hist(x, bins=10, normed = True)
plt.xlabel('x')
plt.ylabel('y')

plt.show()



In [ ]: