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
2) How can I create a loop to save all the plots I created in the loop to a single pdf file?
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
1 |
'fig' + str (j), 'ax' + str (j) = plt.subplots() |
Thank you
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
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 |