This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
"When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck." | |
- James Whitcomb Riley (1849–1916) | |
""" | |
from unittest.mock import Mock, patch | |
################# | |
# MOCK CREATION # | |
################# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def convert_fig_to_html(fig): | |
""" Convert Matplotlib figure 'fig' into a <img> tag for HTML use using base64 encoding. """ | |
import urllib | |
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas | |
import StringIO | |
canvas = FigureCanvas(fig) | |
png_output = StringIO.StringIO() | |
canvas.print_png(png_output) | |
data = png_output.getvalue().encode('base64') |