Skip to content

Instantly share code, notes, and snippets.

@mitjat
Created September 3, 2012 19:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitjat/3612552 to your computer and use it in GitHub Desktop.
Save mitjat/3612552 to your computer and use it in GitHub Desktop.
A drop-in replacement for the udacityplots library
import base64
import json
import matplotlib, matplotlib.pyplot
import numpy
import types
def show_plot(width, height=None):
"""
A decorator -- show the matplotlib plot after `f` completes.
Takes optional parameters (width, height) determining the size of the plot.
"""
def const_decorator(f):
def wrapped_f(*args, **kwargs):
fig=matplotlib.pyplot.figure(figsize=(width, height))
ret = f(*args, **kwargs)
matplotlib.pyplot.show()
return ret
return wrapped_f
if type(width)==types.FunctionType:
f = width
width, height = 9, 4
return const_decorator(f)
else:
return const_decorator
def output_image(*args, **kwargs):
raise NotImplementedError
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment