0

I load in a dataframe with electrical load values for around 2,5 years recorded in a 15 min interval beginning at 2018-04-01 00:15 and ending at 2020-09-03 00:15. Now I want to compare the load for the different years visually.

I display the result in a subplot with the following code:

df_compare = ...imagine this is a large dataframe

years = ['2018', '2019', '2020']

plt.figure()
for i in range(len(years)):
    ax = plt.subplot(len(years), 1, i+1)
    year = years[i]
    result = df_compare[str(year)]
    plt.plot(result['Total_consumption'])
    plt.title(str(year), y=0, loc='left')
plt.show()

The result I get: enter image description here As you can see the months Jan to Mar 2018 are cut off and resized because there are no values existing. The same for Sept to Dec 2020.

The result I want to display is: enter image description here

1 Answer 1

1

you can change the axes limits in your loop:

for i in range(len(years)):
    ax = plt.subplot(len(years), 1, i+1)
    year = years[i]
    result = df_compare[str(year)]
    plt.plot(result['Total_consumption'])
    plt.title(str(year), y=0, loc='left')
    plt.xlim(f'{year}-01-01',f'{year}-12-31')
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you my friend :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.