I am trying to stream a matplotlib generated through pandas df.plot() method but having trouble to get the image rendered on the matplotlib canvas.
Here is what I am doing
import cStringIO
import matplotlib.pyplot as plt
import pandas
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
labels = ['a', 'b', 'c', 'd', 'e']
s = pandas.Series(np.random.randn(5), index=labels)
fig = plt.figure()
s.plot()
canvas = FigureCanvas(fig)
output = cStringIO.StringIO()
canvas.print_png(output)
fh=open('check.png','w')
fh.write(output.getvalue())
the check.png turns out to be blank. I think I am not able to render the plot generated by pandas plot function to canvas.
Second Try: see the axes but no data
import cStringIO
import matplotlib.pyplot as plt
import pandas
import numpy as np
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
labels = ['a', 'b', 'c', 'd', 'e']
s = pandas.Series(np.random.randn(5), index=labels)
fig = plt.figure()
ax = fig.add_subplot(111)
s.plot(ax=ax)
canvas = FigureCanvas(fig)
output = cStringIO.StringIO()
canvas.print_png(output)
fh=open('check.png','w')
fh.write(output.getvalue())
Thanks! -Abhi