%%python module GraphLibrary
from robot.api import logger
import io
import urllib
import base64
import matplotlib.pyplot as plt
class GraphLibrary:
def log_as_graph(self, *args):
"""Log list of values as a graph"""
buffer = io.BytesIO()
# Plot
plt.plot(list(map(float, *args)))
plt.savefig(buffer, format='png')
plt.clf()
# Log
uri = 'data:image/png;base64,' + \
urllib.parse.quote(base64.b64encode(buffer.getvalue()))
html = '<img src="' + uri +'"/>'
logger.info(html, html=True)