我正在尝试返回数据列表和绘图。它们确实显示在 HTML 代码中而不是网页中。当我查看终端时它显示"UserWarning: Starting a Matplotlib GUI outside of the main thread will likely fail."
from io import BytesIO
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import pandas as pd
def extract(request):
if request.method == 'POST':
if request.FILES.get('document'):
file = request.FILES['document']
if 'data' in request.POST:
data = df = pd.read_excel(file)
mpl.rcParams['agg.path.chunksize'] = 10000
plt.plot(data["time"], data["make"], label='male')
plt.plot(data["time"], data["female"], label='female')
plt.xlabel('T')
plt.ylabel('M and F')
plt.legend()
buffer = BytesIO()
plt.savefig(buffer, format='png')
buffer.seek(0)
image_png = buffer.getvalue()
buffer.close() …Run Code Online (Sandbox Code Playgroud)