In [13]:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import plotly.plotly as py
In [14]:
np.random.seed(0)
# create 400 points randomly distributed between -3 and 3 (along x and y)
X = np.random.uniform(-3,3,(400,2))
# points within a circle centered at (1.5, 0) of radius 1 are labeled class +1,
# and -1 otherwise
shift = 1.5
radius = 1
X_shift = X[:,0]-shift
R_shift = np.sqrt(X_shift**2 + X[:,1]**2)
# class labels
Y = np.asarray(map(lambda x: 1 if x else -1, R_shift < radius))
In [15]:
mpl_fig_obj= plt.figure()
# plot 2-d data
plt.scatter(X[:,0], X[:,1], c=Y, cmap=plt.cm.Paired)
fig = plt.gcf()
circle = plt.Circle((shift,0), radius, color='black', fill=False)
fig.gca().add_artist(circle)
fig.gca().set_aspect('equal')
plt.xlabel('x')
plt.ylabel('y')
Out[15]:
In [16]:
#plotly_fig = tls.mpl_to_plotly(mpl_fig_obj)
#plot_url = py.plot(plotly_fig, filename='2d-binaryclass')
py.plot_mpl(mpl_fig_obj, filename = '2d-classification')
Out[16]: