Feb-28-2021, 12:07 PM
Hi,
Refer to the entire code appended at the end. Thanks
1) I meet with "Cannot assign to operator (pyflakes E)" when I try to assign a variable(j) to the name of another variable
Thank you
Refer to the entire code appended at the end. Thanks
1) I meet with "Cannot assign to operator (pyflakes E)" when I try to assign a variable(j) to the name of another variable
'fig' + str(j), 'ax' + str(j) = plt.subplots()2) How can I create a loop to save all the plots I created in the loop to a single pdf file?
Thank you
import xlrd
import openpyxl
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
file_location = "C:/Users/Desktop/Sample1.xlsx"
j=0
wb = xlrd.open_workbook(file_location)
ws = wb.sheet_by_index(0)
x1 = [int(ws.cell_value(i, 0)) for i in range(1,ws.nrows)]
x2 = [int(ws.cell_value(i, 0)) for i in range((ws.nrows-10),ws.nrows)]
for col in range(1,ws.ncols,4):
j+=j
y1 = [ws.cell_value(i, col) for i in range(1,ws.nrows)]
#plt.figure(0)
'fig' + str(j), 'ax' + str(j) = plt.subplots()
'ax'+str(j).plot(x1, y1)
pp = PdfPages('C:/Users/Desktop/Sample1.pdf')
pp.savefig(fig1)
pp.savefig(fig2)
pp.close()
del pp
