def drawScatterChart(self, fileName, sheetName, saveFileName = None): if saveFileName is None: saveFileName = fileName wb = load_workbook(fileName) ws = wb['gegevens'] chart = ScatterChart() chart.title = "Scatter Chart" chart.style = 13 chart.x_axis.scaling.min = 19 chart.x_axis.scaling.max = 31 chart.y_axis.scaling.min = 110 chart.y_axis.scaling.max = 140 chart.x_axis.title = 'gewicht' chart.y_axis.title = 'lengte' chart.legend = None xvalues = Reference(ws, min_col=6, min_row=2, max_row=101) values = Reference(ws, min_col=7, min_row=2, max_row=101) #fill x and y, skip first x=[] y=[] iterrows = iter(ws.rows) next(iterrows) for row in iterrows: x.append(row[5].value) y.append(row[6].value) series = Series(values, xvalues) series.graphicalProperties.line.noFill = True series.marker = marker.Marker('circle', 5.2) chart.series.append(series) # Style the lines s1 = chart.series[0] s1.marker.symbol = "circle" s1.marker.graphicalProperties.solidFill = "4076A9" # Marker filling s1.marker.graphicalProperties.line.solidFill = "4076A9" # Marker outline s1.graphicalProperties.line.noFill = True ws = wb[sheetName] ws.add_chart(chart, "L7") wb.save(saveFileName) area = np.pi * 20 plt.scatter(x, y, s=area, alpha=1) plt.xlabel("gewicht") plt.ylabel("lengte") plt.grid(True,alpha=0.5) plt.axis([19,31,110,140]) plt.show()
def test_from_xml(self, StockChart): from openpyxl.chart.series import Series src = """ <stockChart> <ser> <idx val="0"></idx> <order val="0"></order> </ser> <ser> <idx val="1"></idx> <order val="1"></order> </ser> <ser> <idx val="2"></idx> <order val="2"></order> </ser> <axId val="10"></axId> <axId val="100"></axId> </stockChart> """ node = fromstring(src) chart = StockChart.from_tree(node) assert chart == StockChart(ser=[Series(), Series(), Series()])
def test_ctor(self, StockChart): from openpyxl.chart.series import Series chart = StockChart(ser=[Series(), Series(), Series()]) xml = tostring(chart.to_tree()) expected = """ <stockChart xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"> <ser> <idx val="0" /> <order val="0" /> <spPr> <a:ln > <a:prstDash val="solid" /> </a:ln> </spPr> <marker> <symbol val="none"/> <spPr> <a:ln> <a:prstDash val="solid" /> </a:ln> </spPr> </marker> </ser> <ser> <idx val="1" /> <order val="1" /> <spPr> <a:ln> <a:prstDash val="solid" /> </a:ln> </spPr> <marker> <symbol val="none"/> <spPr> <a:ln> <a:prstDash val="solid" /> </a:ln> </spPr> </marker> </ser> <ser> <idx val="2"></idx> <order val="2"></order> <spPr> <a:ln> <a:prstDash val="solid" /> </a:ln> </spPr> <marker> <symbol val="none"/> <spPr> <a:ln> <a:prstDash val="solid" /> </a:ln> </spPr> </marker> </ser> <axId val="10"></axId> <axId val="100"></axId> </stockChart> """ diff = compare_xml(xml, expected) assert diff is None, diff