matplotlib - speichern, Bild in variable

Würde ich mag, um das Bild zu speichern, erzeugt durch matplotlib in eine variable raw_data, um Sie als inline-image.

import os
import sys
os.environ['MPLCONFIGDIR'] = '/tmp/'
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt

print "Content-type: image/png\n"
plt.plot(range(10, 20))

raw_data = plt.show()

if raw_data:
    uri = 'data:image/png;base64,' + urllib.quote(base64.b64encode(raw_data))
    print '<img src = "%s"/>' % uri
else:
    print "No data"

#plt.savefig(sys.stdout, format='png')

Keine der Funktionen passt zu meinem Anwendungsfall:

  • plt.savefig(sys.stdout, format='png') - Schreibt Sie auf die Standardausgabe. Dies kann helfen.. wie ich das einbetten des Bildes in eine html-Datei.
  • plt.show() /plt.draw() wird nichts ausgeführt, wenn Sie von der Kommandozeile aus
InformationsquelleAutor Ramya | 2011-03-15
Schreibe einen Kommentar