2016-06-20 11 views
0

Ich möchte Plots Nebenhandlungen hinzufügen mitWie Plots Nebenhandlungen hinzufügen matplotlib mit

fig, axarr = plt.subplots(2, 2) 
plt.sca(axarr[0, 0]) 
result = desire_salary.pivot_table('city', 'cult', aggfunc='count') 
axarr[0, 0] = result.plot(kind='bar', alpha=0.75, rot=0, label="Presence/  Absence of cultural centre") 
axarr[0, 0].set_xlabel("Cultural centre") 
axarr[0, 0].set_ylabel("Frequency") 
axarr[0, 0].set_title('Salary and culture') 
axarr[0, 0].plot(result[[0]], color='red') 
plt.sca(axarr[0, 1]) 
axarr[0, 1] = df.plot() 
plt.sca(axarr[1, 0]) 
plt.show() 

Aber man Nebenhandlung hinzugefügt, aber andere nicht. Ich bekomme this graphs Was mache ich falsch?

+0

Wie wäre es 'HALTACHSE ersetzt [ 0, 1] = df.plot() 'mit' df.plot (ax = axarr [0, 1]) '? – SparkAndShine

Antwort

1

Wenn Sie Pandas verwenden (ich nehme an), der sicherste Weg, die, um sicherzustellen, Achsen verwendet wird, ist die Bezugnahme auf die Achsen an die Plotten Funktion zu übergeben mit dem ax= Parameter

fig, axarr = plt.subplots(2, 2) 
result = desire_salary.pivot_table('city', 'cult', aggfunc='count') 
result.plot(kind='bar', alpha=0.75, rot=0, label="Presence/  Absence of cultural centre", ax=axarr[0, 0]) 
axarr[0, 0].set_xlabel("Cultural centre") 
axarr[0, 0].set_ylabel("Frequency") 
axarr[0, 0].set_title('Salary and culture') 
axarr[0, 0].plot(result[[0]], color='red') 


df.plot(ax=axarr[0, 1]) 

plt.show() 
+0

Warum, wenn ich 'fig, axarr = ptlplots (2, 2)' zu 'fig, axarr = pltplots (2, 1)', es 'plt.sca (axarr [0, 1]) zurückgibt IndexError: zu viele Indizes für Array? – ldevyataykina

+0

Wenn Sie 'fig, axarr = ptlplots (2, 1)' tun, haben Sie nur 2 Unterplots in 2 Zeilen, 1 Spalte. In diesem Fall gibt 'subplots' ein 1-dimensionales Array zurück, so dass die gültigen Indizes' axarr [0] 'und' axarr [1] ' –

+0

sind, aber wenn ich 3 Plots haben möchte? 2 oben und 1 unten? – ldevyataykina

Verwandte Themen