Scatter Plot in matplotlib


In [1]:
%load_ext watermark
%watermark -a 'Hideki Tanaka' -u -d -v -p matplotlib,numpy


Hideki Tanaka 
last updated: 2016-02-23 

CPython 3.5.1
IPython 4.1.1

matplotlib 1.5.1
numpy 1.10.4

In [2]:
%matplotlib inline

In [3]:
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import numpy as np

In [4]:
plt.style.use('ggplot')
plt.rc('xtick.major', size=0)
plt.rc('ytick.major', size=0)

In [5]:
np.random.seed(0)

In [6]:
n = 50
x = np.random.rand(n)
y = np.random.rand(n)
z = np.random.rand(n)

In [7]:
fig = plt.figure()
ax = fig.add_subplot(111)
cmap = plt.cm.jet
bounds = np.linspace(0, 1, 11)
norm = colors.BoundaryNorm(bounds, cmap.N)
sc = ax.scatter(x, y, s=500*z, c=z, cmap=cmap, norm=norm, linewidth=0, alpha=0.5)
cb = fig.colorbar(sc, cmap=cmap, norm=norm, boundaries=bounds, ticks=bounds)
ax.set_xlabel('x')
ax.set_ylabel('y')
plt.show()



In [8]:
fig.savefig('../images/mpl_scatterplot.png', dpi=80)