
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python - Plotting charts in excel sheet using openpyxl module
Openpyxl is a Python library using which one can perform multiple operations on excel files like reading, writing, arithmatic operations and plotting graphs.
Example
# import openpyxl module import openpyxl #import BubbleChart,Reference,Series class from openpyxl.chart #sub_module from openpyxl.chart import BubbleChart, Reference, Series # Call a Workbook() function of openpyxl to create a new blank #Workbook object wb = openpyxl.Workbook() # Get workbook active sheetfrom the active attribute. sheet = wb.active rows = [ ("Number of Products", "Sales in USD", "Market share"), (14, 12200, 15), (20, 60000, 33), (18, 24400, 10), (22, 32000, 42), ] #write content of each row in 1st, 2nd and 3rd column of the active #sheet respectively. for row in rows: sheet.append(row) # Create object of BubbleChart class chart = BubbleChart() # create data for plotting xvalues = Reference(sheet, min_col = 1, min_row = 2, max_row = 5) yvalues = Reference(sheet, min_col = 2, min_row = 2, max_row = 5) size = Reference(sheet, min_col = 3, min_row = 2, max_row = 5) # create a 1st series of data series = Series(values = yvalues, xvalues = xvalues, zvalues = size, title ="2013") # add series data to the chart object chart.series.append(series) # set the title of the chart chart.title = " BUBBLE-CHART " # set the title of the x-axis chart.x_axis.title = " X_AXIS " # set the title of the y-axis chart.y_axis.title = " Y_AXIS " # add chart to the sheet the top-left corner of a chart # is anchored to cell E2 sheet.add_chart(chart, "E2") # save the file wb.save("bubbleChart.xlsx")
- Related Articles
- Python - Plotting Area charts in excel sheet using XlsxWriter module
- Python - Plotting bar charts in excel sheet using XlsxWriter module
- Python - Plotting column charts in excel sheet using XlsxWriter module
- Python - Plotting Combined charts in excel sheet using XlsxWriter module
- Python - Plotting Doughnut charts in excel sheet using XlsxWriter module
- Python - Plotting Line charts in excel sheet using XlsxWriter module
- Python - Plotting Pie charts in excel sheet using XlsxWriter module
- Python - Plotting Radar charts in excel sheet using XlsxWriter module
- Python - Plotting scatter charts in excel sheet using XlsxWriter module
- Python - Plotting Stock charts in excel sheet using XlsxWriter module
- Plotting stock charts in excel sheet using xlsxwriter module in python
- Python - Plotting charts in excel sheet with Data Tools using XlsxWriter module
- Python - Plotting Different types of style charts in excel sheet using XlsxWriter module
- How to create charts in excel using Python with openpyxl?
- Python - Writing to an excel file using openpyxl module

Advertisements