Visualization 1: Matplotlib Basics Exercises


In [21]:
%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 [38]:
a = np.random.randn(2,100)
x = a[0,:]
y = a[1,:]
plt.figure(figsize=(5,5))
plt.scatter(x, y, color='green', alpha = 0.9)
plt.xlabel('Random Data')
plt.ylabel('y(Random Data)')


Out[38]:
<matplotlib.text.Text at 0x7f96d3f44550>

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 [46]:
b = np.random.randn(2,100)
x = b[0,:]
y = b[1,:]
plt.hist(x, bins = 10, color = 'orange', alpha = 0.9)
plt.xlabel('This is a histogram')
plt.ylabel('This is still a histogram')


Out[46]:
<matplotlib.text.Text at 0x7f96d398ec10>

In [ ]: