def build_scatter_with_mean_stdev(xvalues_refs, yvalues_refs, stdev_refs, titles, errDir='y'): """Given x values, a list of y values, and the y values' corresponding stdev, it will return a scatter chart with stdev as error bars""" if len(yvalues_refs) != len(stdev_refs) != len(titles): raise ValueError("y-values and stdev list length must be the same") chart = ScatterChart() for xvalues, yvalues, stdev, title in zip(xvalues_refs, yvalues_refs, stdev_refs, titles): # convert reference to data source stdev_data_source = data_source.NumDataSource(numRef=data_source.NumRef(f=stdev)) error_bars = ErrorBars(errDir=errDir, errValType='cust', plus=stdev_data_source, minus=stdev_data_source) series = Series(yvalues, xvalues, title=title) series.errBars = error_bars chart.series.append(series) return chart
chart1.y_axis.scaling.max = 100 # Convert lists of error values to ErrorBars object errorbars = list2errorbars(sorted_plus, sorted_minus, errDir='y') # Set the reference of the bar charts, set categories and shape # Reference the avg across clinician data chart_data1 = Reference(ws1, min_col=3, min_row=37, max_row=52) chart_data2 = Reference(ws1, min_col=4, min_row=37, max_row=52) # Set Up both series series1 = Series(chart_data1, title="Clinician Average Per Question") series2 = Series(chart_data2, title="Average Across Clinicians") # Add error bar to Avg Across Clinician series series2.errBars = errorbars # X Axis categories - Question # cats = Reference(ws1, min_col=1, min_row=37, max_row=52) # Add series to chart chart1.append(series1) chart1.append(series2) # Add data to chart # chart1.add_data(chart_data)#titles_from_data=True chart1.set_categories(cats) # Add the chart to cell "A1", below chart add question list ws1.add_chart(chart1, "A1")