I have the following code that iterates through a data frame row and grabs a start timestamp and an end timestamp from two columns, creating a "time series range", and then plots that time series range from another dataframe of timeseries data. And so, I iterate through each time series range and create the corresponding plot from a for loop. I am using python. Here is my code:
from datetime import datetime
import pandas as pd
import numpy as np
from functools import reduce
pd.options.mode.chained_assignment = None # default='warn'
#Ignore warning messages
from matplotlib import pyplot as plt
from matplotlib.pyplot import figure
import matplotlib as mpl
from datetime import datetime, timedelta
import warnings
warnings.filterwarnings("ignore")
for index, row in log_df.iterrows():
print('Range ID: ' + str(row['cycle_ID']))
start_time_string = row['Start_time']
end_time_string = row['End_time']
start_time = datetime.strptime(start_time_string, '%Y-%m-%d %H:%M:%S')
end_time = datetime.strptime(end_time_string, '%Y-%m-%d %H:%M:%S')
print('Start timestamp: ' + str(start_time))
print('End timestamp: ' + str(end_time))
mask = (data_df['timestamp'] > start_time) & (data_df['timestamp'] <= end_time)
df_masked = data_df.loc[mask]
df_masked
plt.rcParams['figure.figsize'] = [20, 10]
df_masked.plot('localminute' , 'values', legend=False)
plt.xlabel("Timestamp", fontsize=14)
plt.ylabel("Watts", fontsize=14)
plt.show()
This works, however, the problem is that the first plot that gets produced is not formatted with my intended plot size, while all the next plots are. And so the first plot is small, while every plot proceeding is correctly sized. I am confused why this is not working, since I would think my figure size parameter would be applied to each plot within the loop. How can I correctly set my figure size parameter so that every plot is formatted correctly?