Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
print 4 plots using grid area z reshape python meshgrid
def make_meshgrid(x, y, h=.02):
x_min, x_max = x.min() - 1, x.max() + 1
y_min, y_max = y.min() - 1, y.max() + 1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
np.arange(y_min, y_max, h))
return xx, yy
def plot_contours(ax, clf, xx, yy, **params):
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
out = ax.contourf(xx, yy, Z, **params)
return out
def plot_4_classifiers(X,y, classfiers,labels):
fig, sub = plt.subplots(2,2)
plt.subplots_adjust(wspace=0.4, hspace=0.4)
xx, yy = make_meshgrid(X[:,0], X[:,1])
for clf,title, ax in zip(classfiers,range(len(sub.flatten())), sub.flatten()):
plot_contours(ax, clf, xx, yy,, alpha=0.8)
ax.scatter(X[:,0],X[:,1], c=y,, s=20, edgecolors='k')
ax.set_xlim(xx.min(), xx.max())
ax.set_ylim(yy.min(), yy.max())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.