def excel_draw_compare_rw_chart(ws, row_label): '''Warning: Openpyxl currently supports chart creation within a worksheet only. Charts in existing workbooks will be lost''' (row1, row2, row3, row4) = get_comparable_rw_row_idx_by_label(ws, row_label) if not check_comparalbe_rw_row_idxes(ws, row1, row2, row3, row4): return start_col = 2 end_col = ws.get_highest_column() xvalues = Reference(ws, (1, start_col), (1, end_col)) values1 = Reference(ws, (row1, start_col), (row1, end_col)) series1 = Series(values1, title='Write' + ' T', xvalues=xvalues) values2 = Reference(ws, (row2, start_col), (row2, end_col)) series2 = Series(values2, title='Write' + ' MD', xvalues=xvalues) values3 = Reference(ws, (row3, start_col), (row3, end_col)) series3 = Series(values3, title='Read' + ' T', xvalues=xvalues) values4 = Reference(ws, (row4, start_col), (row4, end_col)) series4 = Series(values4, title='Read' + ' MD', xvalues=xvalues) lines = ScatterChart() lines.title = row_label lines.append(series1) lines.append(series2) lines.append(series3) lines.append(series4) ws.add_chart(lines)
def scatter(wb): ws = wb.create_sheet(6, "Scatter") for i in range(10): ws.append([i, i]) chart = ScatterChart() xvalues = Reference(ws, (0, 1), (9, 1)) values = Reference(ws, (0, 0), (9, 0)) series = Series(values, xvalues=xvalues) chart.append(series) ws.add_chart(chart)
def dates(wb): ws = wb.create_sheet(3, "Dates") for i in range(1, 10): ws.append([date(2013, i, 1), i]) chart = BarChart() values = Reference(ws, (1, 2), (9, 2)) labels = Reference(ws, (1, 1), (9, 1)) labels.number_format = 'd-mmm' series = Series(values, labels=labels) chart.append(series) ws.add_chart(chart)
def dates(wb): ws = wb.create_sheet(3, "Dates") for i in range(1, 10): ws.append([date(2013, i, 1), i]) chart = BarChart() values = Reference(ws, (0, 1), (8, 1)) labels = Reference(ws, (0, 0), (8, 0)) labels.number_format = 'd-mmm' series = Series(values, labels=labels) chart.append(series) ws.add_chart(chart)
def letters(wb): ws = wb.create_sheet(2, "Letters") for idx, l in enumerate("ABCDEFGHIJ"): ws.append([l, idx, idx]) chart = BarChart() labels = Reference(ws, (0, 0), (9, 0)) values = Reference(ws, (0, 1), (9, 1)) series = Series(values, labels=labels) chart.append(series) # add second series values = Reference(ws, (0, 2), (9, 2)) series = Series(values, labels=labels) chart.append(series) ws.add_chart(chart)
def numbers(wb): ws = wb.create_sheet(1, "Numbers") for i in range(10): ws.append([i]) chart = BarChart() values = Reference(ws, (0, 0), (9, 0)) series = Series(values) chart.append(series) ws.add_chart(chart)
def line(wb): ws = wb.create_sheet(5, "Line") for i in range(1, 5): ws.append([i]) chart = LineChart() values = Reference(ws, (0, 0), (3,0)) series = Series(values) chart.append(series) ws.add_chart(chart)
def pie(wb): ws = wb.create_sheet(4, "Pie") for i in range(1, 5): ws.append([i]) chart = PieChart() values = Reference(ws, (0, 0), (3, 0)) series = Series(values, labels=values) chart.append(series) ws.add_chart(chart)
def negative(wb): ws = wb.create_sheet(1, "Negative") for i in range(-5, 5): ws.append([i]) chart = BarChart() values = Reference(ws, (0, 0), (9, 0)) series = Series(values) chart.append(series) ws.add_chart(chart)
def toExcelWorkbook(self, sheet): sheet.title = "PREDVAR1" sheet.append(["PREDVAR1 Analysis"]) sheet.append([""]) sheet.append([ "Singular Value Index", "Null-Space term", "Solution-Space term", "Total Variance", "Total STDEV" ]) for sv in self.SingularValueIndices: sheet.append([ sv, self.SolnSpaceTerm[sv], self.NullSpaceTerm[sv], self.TotalVariance[sv], self.TotalVariance[sv]**0.5 ]) from openpyxl.charts import ScatterChart, Reference, Series n = len(self.SingularValueIndices) svref = Reference(sheet, (4, 1), (4 + n, 1)) solref = Reference(sheet, (4, 2), (4 + n, 2)) nullspaceref = Reference(sheet, (4, 3), (4 + n, 3)) totalvarianceref = Reference(sheet, (4, 4), (4 + n, 4)) solspaceseries = Series(solref, "Solution Space Term", xvalues=svref) nullspaceseries = Series(nullspaceref, "Null Space Term", xvalues=svref) totalvarianceseries = Series(totalvarianceref, "Total Variance", xvalues=svref) chart = ScatterChart() chart.append(solspaceseries) chart.append(nullspaceseries) chart.append(totalvarianceseries) sheet.add_chart(chart) chart.title = "Null Space and Solution Space Contribution to Total Variance" chart.x_axis.title = "Singular Value Index" chart.y_axis.title = "Contribution to Total Variance"
def __export_to_xlsx_charts(work_book, scenarios): """recorre los escenarios y creamos los graficos""" scenarios = [scenario for scenario in scenarios if not any([tag in scenario.get('tags', []) for tag in os.environ.get('SKIP_TAGS', '').split(',')])] total_passed = sum(scenario['status'].count("passed") for scenario in scenarios) total_failed = sum(scenario['status'].count("failed") for scenario in scenarios) total_skipped = sum(scenario['status'].count("skipped") for scenario in scenarios) #creamos la pestana y le damos le titulo work_sheet2 = Workbook.create_sheet(work_book) work_sheet2.title = "Metricas" work_sheet2.cell("O2").value = "Test automation rate:" work_sheet2.cell("O3").value = "Autoamatizados:" work_sheet2.cell("P3").value = total_passed + total_failed work_sheet2.cell("O4").value = "Ignorados:" work_sheet2.cell("P4").value = total_skipped #rango de referencia de donde toma los valores el grafico values = Reference(work_sheet2, (3, 16), pos2=(4, 16)) labels = Reference(work_sheet2, (3, 15), pos2=(4, 15)) __add_chart(work_sheet2, values, labels, "Test Automation Rate", top=60) work_sheet2.cell("O6").value = "Test execution status" work_sheet2.cell("P7").value = total_passed work_sheet2.cell("P8").value = total_failed work_sheet2.cell("P9").value = total_skipped work_sheet2.cell("O7").value = "Passed" work_sheet2.cell("O8").value = "Failed" work_sheet2.cell("O9").value = "Skipped" values = Reference(work_sheet2, (7, 16), pos2=(9, 16)) labels = Reference(work_sheet2, (7, 15), pos2=(9, 15)) __add_chart(work_sheet2, values, labels, "Test Automation Rate", top=500)
print("finished in "+str(dt)) speeduptable[int(threadnumber)] = dt logfile.write("threads="+str(threadnumber)+"\t"+str(dt)) if threadnumber <= 1: single_run = dt if single_run is not None: speedup = single_run / dt.real ws.append([threadnumber, dt.real, speedup]) else: ws.append([threadnumber, dt.real]) n = len(sequence) threadref = Reference(ws, (8, 1), (8+n, 1)) runtimeref = Reference(ws, (8, 2), (8+n, 2)) speedupref = Reference(ws, (8, 3), (8+n, 3)) runtimeseries = Series(runtimeref, "Run Time", xvalues=threadref) speedupseries = Series(speedupref, "Speedup", xvalues=speedupref) chart = ScatterChart() chart.append(runtimeseries) chart.append(speedupseries) ws.add_chart(chart) chart.title = "Run Time" chart.x_axis.title = "Number of Threads"
def missing_values(sheet, Reference): vals = [None, None, 1, 2, 3, 4, 5, 6, 7, 8] for idx, val in enumerate(vals, 1): sheet.cell(row=idx, column=3).value = val return Reference(sheet, (1, 3), (10, 3))
def empty_range(sheet, Reference): for i in range(10): sheet.cell(row=i + 1, column=2).value = None return Reference(sheet, (1, 2), (10, 2))
def cell_range(sheet, Reference): return Reference(sheet, (1, 1), (10, 1))
def cell(sheet, Reference): return Reference(sheet, (1, 1))