Skip to content
Snippets Groups Projects
Verified Commit ef78663e authored by jonahbeneb02's avatar jonahbeneb02
Browse files

Show diagram as svg

parent c8b96717
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ from flask import Flask, request, send_from_directory
from flask import render_template
import psycopg2
from matplotlib import pyplot as plt
from io import BytesIO
from io import StringIO
import base64
database = conn = psycopg2.connect(
......@@ -31,13 +31,11 @@ def publishers():
rows = cursor.fetchall()
lists = list(zip(*rows))
buffer = BytesIO()
buffer = StringIO()
fig = plt.figure(figsize = (15, 15))
plt.pie(lists[0], labels = lists[1])
fig.savefig(buffer, format="png")
data = str(base64.b64encode(buffer.getvalue()), "utf-8")
image = f"data:image/png;base64,{data}"
return render_template("publishers.html", title="Publishers", image = image)
fig.savefig(buffer, format="svg")
return render_template("publishers.html", title="Publishers", image = buffer.getvalue())
@app.route("/")
......
......@@ -3,5 +3,7 @@
{% block content %}
<h1>Publishers</h1>
<img width="100%" src="{{ image }}">
<img width="100%">
{{ image | safe }}
</img>
{% endblock content %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment