Last active
August 16, 2017 23:11
-
-
Save kor01/af03bc665aa5e98d8ba446c79ba1f338 to your computer and use it in GitHub Desktop.
[matplot cheet] subplot bars #matplot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.image as mpimg | |
import matplotlib.pyplot as plt | |
import numpy as np | |
%matplotlib inline | |
# Read in and plot the image | |
image = mpimg.imread('Udacican.jpeg') | |
plt.imshow(image) | |
# Take histograms in R, G, and B | |
r_hist = np.histogram(image[:,:,0], bins=32, range=(0, 256)) | |
g_hist = np.histogram(image[:,:,1], bins=32, range=(0, 256)) | |
b_hist = np.histogram(image[:,:,2], bins=32, range=(0, 256)) | |
# Generating bin centers | |
bin_edges = r_hist[1] | |
bin_centers = (bin_edges[1:] + bin_edges[0:len(bin_edges)-1])/2 | |
fig = plt.figure(figsize=(12,3)) | |
plt.subplot(131) | |
plt.bar(bin_centers, r_hist[0]) | |
plt.xlim(0, 256) | |
plt.title('R Histogram') | |
plt.subplot(132) | |
plt.bar(bin_centers, g_hist[0]) | |
plt.xlim(0, 256) | |
plt.title('G Histogram') | |
plt.subplot(133) | |
plt.bar(bin_centers, b_hist[0]) | |
plt.xlim(0, 256) | |
plt.title('B Histogram') | |
plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Put the result into a color plot | |
Z = Z.reshape(xx.shape) | |
plt.contourf(xx, yy, Z, cmap=plt.cm.coolwarm, alpha=0.8) | |
# Plot the training points | |
plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.coolwarm, edgecolors='black') | |
plt.xlim(xx.min(), xx.max()) | |
plt.ylim(yy.min(), yy.max()) | |
plt.xticks(()) | |
plt.yticks(()) | |
plt.title('SVC with '+ker+' kernel', fontsize=20) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment