2 years ago

#74594

test-img

Vuyo

Using Python and xlsxwriter to create a straight line graph with spline interpolation graph

I am look to create a graphs from an 1 excel workbook sheet with 3 sheets. Each sheet should have its own graph. The data is Thermal distribution vs time and it was recorded over three days, hence the three sheets.The graph needs to be a straight line graph with a spline interpolation.

Creating the spline interpolation using xlsxwriter is one of the tricky parts for me. I have this code:

import xlsxwriter
import pandas as pd
import numpy as np

excel_file = 'Thermal_Data_Capture.xlsx'

First_data = pd.read_excel(excel_file, sheet_name='23112021')
Second_data = pd.read_excel(excel_file, sheet_name='24112021')
Third_data = pd.read_excel(excel_file, sheet_name='25112021')
print(First_data.head()


excel_file_path = './Thermal_Distribution_Chart.xlsx'
workbook=xlsxwriter.Workbook(excel_file_path)
First_worksheet=workbook.add_worksheet()

#w

for i,col_name in enumerate(23112021_data.columns):
    First_worksheet.write(0,i,col_name)
    First_worksheet.write_column(1, i, 23112021_data[col_name])



chart = workbook.add_chart({'type' : 'scatter', 'subtype' : 'smooth'})

chart.add_series({'categories': '=Sheet1!$A$2:$A$203',
                       'values': '=Sheet1!$B$2:$B$203',
                       'name': 'TCH1', })
chart.add_series({'categories': '=Sheet1!$A$2:$A$203',
                      'values': '=Sheet1!$C$2:$C$203',
                      'name': 'TCH2'})
chart.add_series({'categories': '=Sheet1!$A$2:$A$203',
                      'values': '=Sheet1!$D$2:$D$203',
                      'name': 'TCH3'})
chart.add_series({'categories': '=Sheet1!$A$2:$A$203',
                      'values': '=Sheet1!$E$2:$E$203',
                      'name': 'TCH4'})
chart.add_series({'categories': '=Sheet1!$A$2:$A$203',
                      'values': '=Sheet1!$F$2:$F$203',
                      'name': 'TCH5'})
chart.add_series({'categories': '=Sheet1!$A$2:$A$203',
                      'values': '=Sheet1!$G$2:$G$203',
                    'name': 'TCH6'})


First_worksheet.insert_chart('I3', chart)

workbook.close()

python

xlsxwriter

0 Answers

Your Answer

Accepted video resources