Last active
September 6, 2024 07:26
Box and Whisker Chart Maker in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aspose.slides as slides | |
# Instantiate an instance of the Presentation class. | |
with slides.Presentation() as pres: | |
# Add a Box and Whisker chart to the first slide at the specified position and size. | |
chart = pres.slides[0].shapes.add_chart(slides.charts.ChartType.BOX_AND_WHISKER, 50, 50, 500, 400) | |
# Clear the existing categories and series from the chart data | |
chart.chart_data.categories.clear() | |
chart.chart_data.series.clear() | |
wb = chart.chart_data.chart_data_workbook | |
wb.clear(0) | |
# Add new categories to the chart | |
chart.chart_data.categories.add(wb.get_cell(0, "A1", "Category 1")) | |
chart.chart_data.categories.add(wb.get_cell(0, "A2", "Category 1")) | |
chart.chart_data.categories.add(wb.get_cell(0, "A3", "Category 1")) | |
chart.chart_data.categories.add(wb.get_cell(0, "A4", "Category 1")) | |
chart.chart_data.categories.add(wb.get_cell(0, "A5", "Category 1")) | |
chart.chart_data.categories.add(wb.get_cell(0, "A6", "Category 1")) | |
# Add a new series to the chart for the Box and Whisker data | |
series = chart.chart_data.series.add(slides.charts.ChartType.BOX_AND_WHISKER) | |
series.quartile_method = slides.charts.QuartileMethodType.EXCLUSIVE | |
# Configure the series to show additional visual elements in the chart | |
series.show_mean_line = True | |
series.show_mean_markers = True | |
series.show_inner_points = True | |
series.show_outlier_points = True | |
# Add data points to the series for each category, setting values for the Box and Whisker chart | |
series.data_points.add_data_point_for_box_and_whisker_series(wb.get_cell(0, "B1", 15)) | |
series.data_points.add_data_point_for_box_and_whisker_series(wb.get_cell(0, "B2", 41)) | |
series.data_points.add_data_point_for_box_and_whisker_series(wb.get_cell(0, "B3", 16)) | |
series.data_points.add_data_point_for_box_and_whisker_series(wb.get_cell(0, "B4", 10)) | |
series.data_points.add_data_point_for_box_and_whisker_series(wb.get_cell(0, "B5", 23)) | |
series.data_points.add_data_point_for_box_and_whisker_series(wb.get_cell(0, "B6", 16)) | |
# Save the presentation with the new Box chart to a PPT/PPTX file. | |
pres.save("./box_chart_out.ppt", slides.export.SaveFormat.PPT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment