46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
|
import os
|
||
|
import glob
|
||
|
import pandas as pd
|
||
|
import matplotlib
|
||
|
matplotlib.use('Agg')
|
||
|
import matplotlib.pyplot as plt
|
||
|
|
||
|
def createGraphics(df: pd.DataFrame):
|
||
|
# для сохранения диаграммы в конкретной папке
|
||
|
script_dir = os.path.dirname(__file__)
|
||
|
results_dir = os.path.join(script_dir, '../static/')
|
||
|
|
||
|
if not os.path.isdir(results_dir):
|
||
|
os.makedirs(results_dir)
|
||
|
|
||
|
# ax = plt.gca()
|
||
|
#
|
||
|
# df.plot(kind='line', x='Store_Area', y='Items_Available', color='red', ax=ax)
|
||
|
# df.plot(kind='line', x='Store_Area', y='Daily_Customer_Count', color='yellow', ax=ax)
|
||
|
|
||
|
df.plot(x="Items_Available", y="Store_Area", kind="bar")
|
||
|
|
||
|
plt.savefig(results_dir + 'file' + str(1) + '.jpg')
|
||
|
|
||
|
plt.close()
|
||
|
|
||
|
df.boxplot(column=['Store_Area', 'Items_Available', 'Daily_Customer_Count'])
|
||
|
|
||
|
plt.savefig(results_dir + 'file' + str(2) + '.jpg')
|
||
|
|
||
|
plt.close()
|
||
|
|
||
|
df.boxplot(column=['Store_Sales'])
|
||
|
|
||
|
plt.savefig(results_dir + 'file' + str(3) + '.jpg')
|
||
|
|
||
|
plt.close()
|
||
|
|
||
|
# # сразу загружаем все созданные png файлы
|
||
|
# results_dir = os.path.join(script_dir, 'static/*')
|
||
|
#
|
||
|
# files = glob.glob(results_dir)
|
||
|
#
|
||
|
# return files
|
||
|
|
||
|
return True
|