Я создал сводную таблицу и попытался построить ее в Flask, как показано ниже:
def create_figure():
fig = Figure()
axis = fig.add_subplot(1, 1, 1)
data = pd.read_excel('C:/Users/Ahmed Mustafa/FlaskProject/app/templates/sample.xlsx',0)
data.set_index(['TicketNumber'], inplace=True)
data.index.name=None
tickets = data.loc[data.Status=='Closed']
Pivotcountg = data.groupby("NewGroup")
Pivotcountg = Pivotcountg.agg({"NewStatus": "nunique"})
Pivotcountg = Pivotcountg.reset_index()
Pivotcount = data.groupby('NewGroup').count()
Pivotcountp = Pivotcountg.plot.bar()
Но когда я попытался построить ее, как показано ниже:
@main_blueprint.route('/plot.png')
def plot_png():
fig = create_figure()
output = io.BytesIO()
FigureCanvas(fig).print_png(output)
return Response(output.getvalue(), mimetype='image/png')
def create_figure():
fig = Figure()
axis = fig.add_subplot(1, 1, 1)
data = pd.read_excel('C:/Users/Ahmed Mustafa/FlaskProject/app/templates/sample.xlsx',0)
data.set_index(['TicketNumber'], inplace=True)
data.index.name=None
tickets = data.loc[data.Status=='Closed']
Pivotcountg = data.groupby("NewGroup")
Pivotcountg = Pivotcountg.agg({"NewStatus": "nunique"})
Pivotcountg = Pivotcountg.reset_index()
Pivotcount = data.groupby('NewGroup').count()
Pivotcountp = Pivotcountg.plot.bar()
axis.plot(Pivotcountp)
return fig
не работает!
я включил строку ниже в мой html файл:
<img src="/plot.png" alt="my plot">