Seite 1 von 1

Subplots in subplots

Verfasst: Donnerstag 11. Mai 2017, 20:59
von SIto
Hallo zusammne,

ich würde gerne 2x3 subplots erstellen, wobei jeder subplot wiederum aus drei subplots besteht.
In Bildern:
Bild
Es sollen also sechs Bilder wie rechts, an die jeweiligen Stellen im linken Bild gelegt werden. Die Funktionen im linken Bild sind völlig willkürlich und sollen nur zur Illustration dienen.

Der Code den ich soweit habe ist:

Code: Alles auswählen

#Linkes Bild
fig = plt.figure()
gs = gridspec.GridSpec(2, 3)
ax1 = fig.add_subplot(gs[0,0])

ax2 = fig.add_subplot(gs[0,1])
ax2.plot([1,2,3,4], [1,4,9,16], 'k-')
ax3 = fig.add_subplot(gs[0, 2])
ax3.plot([1,2,3,4], [1,10,100,1000], 'b-')
ax4 = fig.add_subplot(gs[1,0])
ax4.plot([1,2,3,4], [0,0,1,1], 'g-')
ax5 = fig.add_subplot(gs[1,1])
ax5.plot([1,2,3,4], [1,0,0,1], 'c-')
gs.update(wspace=0.5, hspace=0.5)
ax5 = fig.add_subplot(gs[1,2])
ax5.plot([1,2,3,4], [1,0,0,1], 'c-')
gs.update(wspace=0.5, hspace=0.5)

#Rechtes Bild
fig, (ax1, ax2, ax3) = plt.subplots(3, sharex=True, sharey=True)

ax1.plot (x[1: -1] , ev[:,1], label =r"$\psi_{%d}(x)$" % i)
ax1.set_title(r'$\psi_n$ berechet mit eig, eigh und eigsh')
ax2.plot (x[1: -1] , evh[:,1], label =r"$\psi_{%d}(x)$" % i)
ax3.plot (x[1: -1] , evs[:,1], label =r"$\psi_{%d}(x)$" % i)

fig.subplots_adjust(hspace=0)
plt.setp([a.get_xticklabels() for a in fig.axes[:-1]], visible=False)

Wäre für ein bisschen Hilfe dankbar.^^
Gruss Sito

Re: Subplots in subplots

Verfasst: Samstag 20. Mai 2017, 20:02
von pixewakb
stackoverflow kennst Du? Ich würde die Frage dort noch mal stellen.

Seit einigen Tagen mühe ich mich auch mit mpl ab und kann nur sagen, dass die meisten Beispiele im Netz bei mir nicht lauffähig sind. Die Dokumentation ist nicht so erfreulich, aber es gibt Funktionen, die momentan leider nur mpl bietet. Ich hoffe, dass ich noch den Durchblick bekomme.

Re: Subplots in subplots

Verfasst: Dienstag 23. Mai 2017, 03:38
von BigZ
Ich weiß zwar nicht was ev, evh oder evs ist, aber mit GridSpecFromSubplot kannst du 1*2 Plots erstellen, wovon der erste 2*3 Plots enthält und der zweite 3*1

Code: Alles auswählen

import matplotlib.pyplot as plt
from matplotlib import gridspec

X, Y = [0,1,2,3], [4,4,4,5]

gs0 = gridspec.GridSpec(1, 2)

gs00 = gridspec.GridSpecFromSubplotSpec(2, 3, subplot_spec=gs0[0])
ax1 = plt.subplot(gs00[0, 0])
ax1.plot([1,2,3,4], [1,4,9,16], 'k-')
ax2 = plt.subplot(gs00[0, 1])
ax2.plot([1,2,3,4], [1,10,100,1000], 'b-')
ax3 = plt.subplot(gs00[0, 2])
ax3.plot([1,2,3,4], [0,0,1,1], 'g-')

ax4 = plt.subplot(gs00[1, 0])
ax4.plot([1,2,3,4], [1,0,0,1], 'c-')
ax5 = plt.subplot(gs00[1, 1])
ax5.plot([1,2,3,4], [1,0,0,1], 'c-')
ax6 = plt.subplot(gs00[1, 2])
ax6.plot(X, Y)

gs01 = gridspec.GridSpecFromSubplotSpec(3, 1, subplot_spec=gs0[1])
ax1 = plt.subplot(gs01[0])
ax1.plot(X, Y)
ax2 = plt.subplot(gs01[1])
ax2.plot(X, Y)
ax3 = plt.subplot(gs01[2])
ax3.plot(X, Y)


plt.show()