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

Show diagram as svg

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