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 [4]:
# This assignment wasn't graded for some reason, having a 0.0/0.0 score. Resubmitting the assignment for grading on this one
# as well as on the Theory and Practice problems.

plt.xlabel('Random x-data')
plt.ylabel('Random y-data')
plt.title('Random Numbers')
plt.scatter(np.random.randn(50),np.random.randn(50), color='b', alpha=.75);


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 [5]:
bins=20
plt.hist(np.random.randn(1000),bins, color='r')
plt.ylabel('Occurrence of number')
plt.xlabel('Random Numbers')
plt.title('Random Number Histogram');



In [ ]: