Ich versuche, ein Bild mit seinem jeweiligen Histogramm nebeneinander mit gleichem Anteil zu plotten, indem ich plt.fig()
in Python verwende, aber ich bekomme nicht die gewünschte Ausgabe. Stattdessen bekomme ich das Histogramm überlappend auf das Bild.Wie zeichne ich ein Bild und ein Diagramm nebeneinander?
Eine Idee, warum das so weitergeht?
import pylab as plt
import matplotlib.image as mpimg
import numpy as np
img = np.uint8(mpimg.imread('motherT.png'))
im2 = np.uint8(mpimg.imread('waldo.png'))
# convert to grayscale
# do for individual channels R, G, B, A for nongrayscale images
img = np.uint8((0.2126* img[:,:,0]) + \
np.uint8(0.7152 * img[:,:,1]) +\
np.uint8(0.0722 * img[:,:,2]))
im2 = np.uint8((0.2126* img[:,:,0]) + \
np.uint8(0.7152 * img[:,:,1]) +\
np.uint8(0.0722 * img[:,:,2]))
# show old and new image
# show original image
fig = plt.figure()
plt.imshow(img)
plt.title(' image 1')
plt.set_cmap('gray')
# show original image
fig.add_subplot(221)
plt.title('histogram ')
plt.hist(img,10)
plt.show()
fig = plt.figure()
plt.imshow(im2)
plt.title(' image 2')
plt.set_cmap('gray')
fig.add_subplot(221)
plt.title('histogram')
plt.hist(im2,10)
plt.show()
Vielleicht hilft: [zu versuchen, Position Nebenhandlungen neben einander] (http://stackoverflow.com/questions/1616427/trying-to-position-subplots-next-to-each-other) –