Visualization 1: Matplotlib Basics Exercises


In [50]:
%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 [51]:
?plt.scatter()

In [60]:
from matplotlib import markers
markers.MarkerStyle.markers.keys()

x = np.random.rand(100)
y = np.random.rand(100)
plt.scatter(x, y, label = 'The Dots', c = u'r', marker = u'o')
plt.grid(True)
plt.box(False)
plt.xlabel('The X-Axis')
plt.ylabel('The Y-Axis')
plt.legend(loc=0) ##I have no idea if you wanted a legend... but I tried to find the best place for it


Out[60]:
<matplotlib.legend.Legend at 0x7fdea880d750>

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 [66]:
data = np.random.rand(100)
data

?plt.hist()

plt.hist(data, bins = 30, histtype = u'step', color = 'g')
plt.box(True)
plt.xlabel('The X-Axis for Histograms')
plt.ylabel('The Y-Axis for Histograms')


Out[66]:
<matplotlib.text.Text at 0x7fdea85bf2d0>

In [ ]: