Aditya Aditya - 7 months ago 52
Python Question

Unable to PLOT multiple data from EXCEL using MATPLOTLIB

I've an Excel file with 1000 rows & 300 columns.
I want to plot (column 1) vs (column 2 to 288); my 1st Column is my X Axis, and the rest of the columns are on the Y axis.
My code is below; I get no display.
There's no error message as such.

from openpyxl import load_workbook
import numpy as np
import matplotlib.pyplot as plt

wb = load_workbook('CombinedData1.xlsx')
sheet_1 = wb.get_sheet_by_name('CombinedData')

x = np.zeros(sheet_1.max_row)
y = np.zeros(sheet_1.max_row)
a = np.zeros(sheet_1.max_column)
b = np.zeros(sheet_1.max_column)

print (sheet_1.max_row)
print (sheet_1.max_column)

for i in range(0, sheet_1.max_row):
for j in range(1, 7):
x[i] = sheet_1.cell(row=i + 1, column=j).value
y[j] = sheet_1.cell(row=i + 1, column=j).value
# z[i] = sheet_1.cell(row=i + 1, column=3).value
print x[i]
# print y[i]
plt.plot(x[i], y[i], 'bo-', label='Values')



I would consider using pandas:

import pandas
df = pandas.read_excel('CombinedData1.xlsx', sheetname='CombinedData', header=None)


plt.plot(df[0], df[1])