Visualization 1: Matplotlib Basics Exercises


In [1]:
%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 [31]:
x = np.random.rand(100)
y = np.random.rand(100)
plt.scatter(x, y, color='orange', s=70, alpha=0.8)
plt.xlabel('X')
plt.ylabel('Y')
plt.title('X v. Y Scatter')


Out[31]:
<matplotlib.text.Text at 0x7f5f4b77c850>

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 [19]:
x = np.random.rand(100)
plt.hist(x, bins=25, color='green')
plt.xlabel('X')
plt.ylabel('Y(X)')
plt.title('Random Histogram')


Out[19]:
<matplotlib.text.Text at 0x7f5f4bff8a10>

In [ ]: