Python third-party library OPENPYXL (4)

Source: Internet
Author: User

Python third-party library OPENPYXL (4)Column Chart

In a histogram, the values are plotted as horizontal bars or vertical columns.

Vertical, horizontal, and stacked bar charts.

Note : The following settings affect different chart types

1. Toggle between vertical and horizontal bar charts, set to Col or bar, respectively

2. When using a stacked chart, the overlap needs to be set to 100

3. If the bar is horizontal, the x-axis and y-axis are reversed

 fromOpenpyxlImportWorkbook fromOpenpyxl.chartImportBarchart, Series, Referencewb= Workbook (write_only=True) WS=wb.create_sheet () rows= [    (' Number','Batch 1','Batch 2'),    (2, 10, 30),    (3, 40, 60),    (4, 50, 70),    (5, 20, 10),    (6, 10, 40),    (7, 50, 30),] forRowinchrows:ws.append (Row) Chart1=Barchart () Chart1.type="Col"Chart1.style= 10Chart1.title="Bar Chart"Chart1.y_axis.title='Test Number'Chart1.x_axis.title='Sample Length (mm)'Data= Reference (WS, min_col=2, Min_row=1, max_row=7, max_col=3) Cats= Reference (WS, Min_col=1, min_row=2, max_row=7) chart1.add_data (data, Titles_from_data=True) Chart1.set_categories (cats) Chart1.shape= 4Ws.add_chart (Chart1,"A10") fromCopyImportDeepcopychart2=deepcopy (Chart1) Chart2.style= 11Chart2.type="Bar"Chart2.title="Horizontal Bar Chart"Ws.add_chart (Chart2,"G10") Chart3=deepcopy (Chart1) Chart3.type="Col"Chart3.style= 12chart3.grouping="Stacked"Chart3.overlap= 100Chart3.title='Stacked Chart'Ws.add_chart (CHART3,"A27") Chart4=deepcopy (Chart1) Chart4.type="Bar"Chart4.style= 13chart4.grouping="percentstacked"Chart4.overlap= 100Chart4.title='Percent Stacked Chart'Ws.add_chart (CHART4,"G27") Wb.save ("bar.xlsx")
Run results

3D Bar Chart
 fromOpenpyxlImportWorkbook fromOpenpyxl.chartImport(Reference, Series, Barchart3d,) WB=Workbook () WS=wb.activerows=[(None,2013, 2014),    ("Apples", 5, 4),    ("oranges", 6, 2),    ("Pears", 8, 3)] forRowinchrows:ws.append (ROW) data= Reference (WS, min_col=2, Min_row=1, max_col=3, max_row=4) Titles= Reference (WS, Min_col=1, min_row=2, max_row=4) Chart=Barchart3d () chart.title="3D Bar Chart"Chart.add_data (Data=data, Titles_from_data=True) chart.set_categories (titles) Ws.add_chart (chart,"E5") Wb.save ("bar3d.xlsx")
Run Results

Python third-party library OPENPYXL (4)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.