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 [3]:
y=np.random.randn(30)
x=np.random.randn(30)

plt.scatter(x,y, color="r",s=50, marker='x',alpha=.9)
plt.xlabel('Random Values for X')
plt.ylabel('Randome Values for Y')
plt.title("My Random Values")


Out[3]:
<matplotlib.text.Text at 0x7fb032ae6450>

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 [4]:
data=np.random.randn(50)
plt.hist(data, bins=10,color='g',align='left')
plt.xlabel('Value')
plt.ylabel('Number of Random Numbers')
plt.title('My Histogram')


Out[4]:
<matplotlib.text.Text at 0x7fb0329e6b10>

In [ ]: