overlay-matplotlib imshow mit line-plots, die sind in einem raster angeordnet

Möchte ich zum Plotten eine Reihe von Kurven, die über ein Bild

Mit diesem code, ich bin ziemlich nahe:

G=plt.matplotlib.gridspec.GridSpec(64,1)
fig = plt.figure()
plt.imshow(img.data[:,:],cmap='gray')
plt.axis('off')
plt.axis([0,128,0,64])
for i in arange(64):
    fig.add_subplot(G[i,0])
    plt.axis('off')
    # note that vtc.data.shape = (64, 128*400=51200)
    # so every trace for each image pixel is 400 points long
    plt.plot(vtc.data[i,:])
    plt.axis([0, 51200, 0, 5])

Dem Ergebnis, das ich bekomme sieht wie folgt aus:
overlay-matplotlib imshow mit line-plots, die sind in einem raster angeordnet

Das problem ist, dass, während ich scheinen in der Lage sein, um loszuwerden, alle die Polsterung in der horizontalen (x -) Richtung, gibt es unterschiedliche Höhe der Polsterung in der Bild und die gestapelten Diagramme in vertikaler Richtung.

Versuchte ich mit

ax = plt.gca()
ax.autoscale_view('tight')

aber nicht reduzieren die Marge entweder.

Wie kann ich ein Gitter von m-von-n line plots, line-up genau mit einem in die Luft gesprengt (um den Faktor f) version eines Bildes mit den Maßen (fm)-durch-(fn)?


UPDATE und Lösung:
Die Antwort von @RutgerKassies funktioniert ganz gut. Ich erreichte es mit seinem code so:

fig, axs = plt.subplots(1,1,figsize=(8,4))
axs.imshow(img.data[:,:],cmap='gray', interpolation='none')
nplots = 64
fig.canvas.draw()
box = axs._position.bounds
height = box[3] / nplots
for i in arange(nplots):
    tmpax = fig.add_axes([box[0], box[1] + i * height, box[2], height])
    tmpax.set_axis_off()
    # make sure to get image orientation right and 
    tmpax.plot(vtc.data[nplots-i-1,:],alpha=.3)
    tmpax.set_ylim(0,5)
    tmpax.set_xlim(0, 51200)

overlay-matplotlib imshow mit line-plots, die sind in einem raster angeordnet

InformationsquelleAutor DrSAR | 2013-05-30
Schreibe einen Kommentar