Esempio n. 1
0
    def plot_area(self, sheetname, column, value):
        # 必要な値と項目を残した時系列データを作成
        df = self._df[[value, column]].pivot_table(index = "DateTime", values = value, columns = column, fill_value = 0)

        with pd.ExcelWriter(self._file) as writer:
            # excelファイルがあるなら追加書きする
            if os.path.isfile(self._file):
                writer.book = load_workbook(self._file)

            # write the df on excel at once
            df.to_excel(writer, sheet_name = sheetname)

            # plot Area chart
            chart = AreaChart()
            chart.grouping = "stacked"
            self._plot(writer.book[sheetname], chart, title = "面グラフ", xlabel = "日付", ylabel = "回数")
Esempio n. 2
0
def area_max(df, wb, sheet_name):
    df_columns = df.columns.tolist()
    ws = wb[sheet_name]

    chart = AreaChart()
    chart.height = 15
    chart.width = 30
    chart.x_axis.title = df_columns[1]
    chart.y_axis.title = None
    chart.grouping = "percentStacked"
    chart.title = sheet_name

    episodes = Reference(ws, min_col=df_columns.index('episode') + 1, min_row=2, max_row=len(df) + 1)
    data = Reference(ws, min_col=df_columns.index('happy') + 1, min_row=1, max_col=len(df_columns), max_row=len(df) + 1)
    chart.add_data(data, titles_from_data=True)
    chart.set_categories(episodes)

    ws.add_chart(chart, f"A{len(df) + 3}")
Esempio n. 3
0
                    i, j + initial_col, cell))
                ws.cell(row=i, column=j + initial_col, value=int(cell))
            else:
                ws.cell(row=i, column=j + initial_col, value=cell)
                logger.info("Adding {} cols".format(len(row)))
        i += 1

    final_row = i - 1
logger.info("Final Row: {}, Final Col: {}".format(final_row, final_col))
table_range = "{}{}:{}{}".format(
    openpyxl.utils.cell.get_column_letter(initial_col), initial_row,
    openpyxl.utils.cell.get_column_letter(final_col), final_row)
logger.info("Setting table range to {}".format(table_range))
table.ref = table_range

# Add Routing StackedLine Chart

chart = AreaChart()
data = Reference(ws,
                 min_col=2,
                 min_row=1,
                 max_col=final_col,
                 max_row=final_row)
cats = Reference(ws, min_col=1, min_row=1, max_col=1, max_row=final_row)
chart.add_data(data, titles_from_data=True)
chart.grouping = "percentStacked"
chart.set_categories(cats)
ws.add_chart(chart, "H1")

wb.save(filename=args.output)
import openpyxl
from openpyxl.chart import AreaChart, Reference

wb = openpyxl.load_workbook(r"..\data\area_chart.xlsx")
sh = wb.active

data = Reference(sh, min_col=3, max_col=7, min_row=1, max_row=sh.max_row)
labels = Reference(sh, min_col=2, max_col=2, min_row=2, max_row=sh.max_row)
chart = AreaChart()
chart.grouping = "stacked"
#chart.grouping = "percentStacked"
chart.title = "分類別売上(サイズ積上げ)"
chart.x_axis.title = "分類"
chart.y_axis.title = "サイズ"
chart.add_data(data, titles_from_data=True)
chart.set_categories(labels)

sh.add_chart(chart, "I2")
wb.save(r"..\data\area_chart.xlsx")