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 [2]:
np.random.randn
plt.scatter


Out[2]:
<function matplotlib.pyplot.scatter>

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 [22]:
q = np.random.randn(2,10)
q


Out[22]:
array([[-0.90898007,  0.5193011 , -1.10707952,  1.26726471, -0.41094917,
         0.91940895, -1.63949744,  0.73561594,  0.58551354, -0.65256069],
       [ 0.8878641 ,  1.03223236,  1.28499123,  0.65048455,  1.17057279,
        -0.27987838, -0.33490126,  1.04880152,  0.50940839,  0.92840605]])

In [23]:
plt.hist(q[:,0],q[:,1])


Out[23]:
(array([ 1.]), array([ 0.5193011 ,  1.03223236]), <a list of 1 Patch objects>)

In [ ]: