Warum ist mein plt.savefig nicht funktioniert?
Habe ich ein einfaches python-code wie folgt:
import numpy as np
import matplotlib.pyplot as plt
"""
Here are the solutions and the plot.
"""
# Create the axis and plot.
plt.axis([0, 10, 0, 10])
axis_x = range(1, 11)
grd = [1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1, 8.1, 9.1, 10.1]
grd2 = [1.2, 2.2, 3.2, 4.2, 5.2, 6.2, 7.2, 8.2, 9.2, 10.2]
plt.plot(axis_x, grd, '-g', label='BR1')
plt.plot(axis_x, grd2, '-b', label='BR2')
plt.legend(loc='upper left')
plt.grid()
plt.show()
# Save the results vector to a text file.
np.savetxt('test.out', (grd, grd2))
# Save the figure as '.eps' file.
plt.savefig('expl.pdf', format='pdf', dpi=1200)
Wenn ich öffnen Sie die Ausgabe-Dateien expl.pdf
- und/oder test.out
ich finde Sie leer sind und nichts vorhanden ist. Warum?
Dank.
InformationsquelleAutor Jika | 2015-06-10
Du musst angemeldet sein, um einen Kommentar abzugeben.
Wenn Sie das Bild schließen, das angezeigt
plt.show()
, das Bild ist geschlossen und aus dem Speicher freigegeben.Sollten Sie rufen
savefig
undsavetxt
vor dem Aufrufshow
.test.out
ist noch leer.InformationsquelleAutor shx2
Ihrem Grundstück kann nicht erzeugt werden, da Sie definiert die Liste
axis_x
er nur die Länge 9, währendgrd
undgrd2
haben die Länge gleich 10 ist.Ersetzen Sie einfach die definition von
axis_x
mit:axis_x=range(1,11)
und das Grundstück wird angezeigt, und es wird gespeichert OK.
axis_x=range(1,11)
- und nun meine Antwort sieht aus wie unangemessen 🙂InformationsquelleAutor xecafe