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 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 __add_chart(work_sheet, values, labels, title, top=400): """add chart""" series = Series(values, title=title, labels=labels, color=Color(colors.GREEN)) chart = PieChart() chart.append(series) chart.drawing.top = top chart.drawing.left = 10 work_sheet.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 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, (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)
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" chart.y_axis.title = "Run Time [sec]" logfile.close() outfile = femfilename+".parperformance.xlsx"
def series(cell_range, Series): return Series(values=cell_range)