Skip to content

Instantly share code, notes, and snippets.

@vincentchu
Created June 14, 2013 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vincentchu/5779409 to your computer and use it in GitHub Desktop.
Save vincentchu/5779409 to your computer and use it in GitHub Desktop.
Playing with matplotlib
rcOpts = {'figure.figsize': (6.0,4.0),
# play nicely with white background in the Qt and notebook frontend
'figure.facecolor': 'white',
'figure.edgecolor': 'white',
# 12pt labels get cutoff on 6x4 logplots, so use 10pt.
'font.size': 10,
# 72 dpi matches SVG/qtconsole
# this only affects PNG export, as SVG has no dpi setting
'savefig.dpi': 72,
# 10pt still needs a little more room on the xlabel:
'figure.subplot.bottom' : .125
}
from io import BytesIO
import base64
import matplotlib
# matplotlib.interactive(True)
matplotlib.interactive(False)
from matplotlib import pyplot
pyplot.rcParams.update(rcOpts)
from pylab import *
from matplotlib._pylab_helpers import Gcf
plot([1,2,3])
fig = Gcf.get_all_fig_managers()[0].canvas.figure
fc = fig.get_facecolor()
ec = fig.get_edgecolor()
bytes_io = BytesIO()
fig.canvas.print_figure(bytes_io, format='png', bbox_inches='tight', facecolor=fc, edgecolor=ec)
data = bytes_io.getvalue()
print("DATA = %s" %(base64.b64encode(data)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment