Export plot to svg instead of png
This commit is contained in:
parent
0e16891961
commit
0eb3bb6b91
@ -13,7 +13,7 @@
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
<img src="{{ image|safe }}"/>
|
{{ image|safe }}
|
||||||
{{ tables|safe }}
|
{{ tables|safe }}
|
||||||
</main>
|
</main>
|
||||||
</article>
|
</article>
|
||||||
|
|||||||
17
wsgi.py
17
wsgi.py
@ -1,4 +1,3 @@
|
|||||||
import base64
|
|
||||||
import datetime
|
import datetime
|
||||||
import io
|
import io
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
@ -11,7 +10,6 @@ import numpy as np
|
|||||||
import pandas as pd
|
import pandas as pd
|
||||||
from flask import Flask, render_template, request
|
from flask import Flask, render_template, request
|
||||||
from flask_caching import Cache
|
from flask_caching import Cache
|
||||||
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
|
|
||||||
|
|
||||||
from download_digital import construct_dataframe, get_bez_data
|
from download_digital import construct_dataframe, get_bez_data
|
||||||
|
|
||||||
@ -84,7 +82,7 @@ def plot(
|
|||||||
sum_val = current_df[["Digitale Befragung"]].sum().iloc[0]
|
sum_val = current_df[["Digitale Befragung"]].sum().iloc[0]
|
||||||
df.loc[datetime.datetime.now()] = sum_val
|
df.loc[datetime.datetime.now()] = sum_val
|
||||||
|
|
||||||
plt.figure(dpi=300)
|
fig = plt.figure(dpi=300)
|
||||||
|
|
||||||
# fill weekends
|
# fill weekends
|
||||||
max_date = max(data_dict.keys())
|
max_date = max(data_dict.keys())
|
||||||
@ -155,15 +153,12 @@ def plot(
|
|||||||
plt.axhline(y=total_target, color="#48a9be", linestyle="--")
|
plt.axhline(y=total_target, color="#48a9be", linestyle="--")
|
||||||
plt.tight_layout()
|
plt.tight_layout()
|
||||||
|
|
||||||
# Convert plot to PNG image
|
# Convert plot to SVG image
|
||||||
pngImage = io.BytesIO()
|
imgdata = io.StringIO()
|
||||||
FigureCanvas(plt.gcf()).print_png(pngImage)
|
fig.savefig(imgdata, format="svg")
|
||||||
|
svgImage.seek(0) # rewind the data
|
||||||
|
|
||||||
# Encode PNG image to base64 string
|
return svgImage.read()
|
||||||
pngImageB64String = "data:image/png;base64,"
|
|
||||||
pngImageB64String += base64.b64encode(pngImage.getvalue()).decode("utf8")
|
|
||||||
|
|
||||||
return pngImageB64String
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user