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 [32]:
a=np.random.randn(2,10)
x=a[0,:]
x
y=a[1,:]
y

plt.scatter(x,y,color='red')
plt.grid(True)
plt.box(False)
plt.xlabel('random x values')
plt.ylabel('random y values')
plt.title('TITLE')


Out[32]:
<matplotlib.text.Text at 0x7f8cebc0bad0>

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 [54]:
a=np.random.randn(1,10)
x=a[0,:]
plt.hist(x,bins=15,histtype='bar',color='green')
plt.title('MY HISTOGRAM')
plt.xlabel('RANDOM X VALUES')
plt.ylabel('FREQUENCY')


Out[54]:
<matplotlib.text.Text at 0x7f8ceac9bd50>

In [ ]: