У меня такой код:
import pandas as pd
from matplotlib import pyplot as plt
%matplotlib inline
hours = list(range(25)) # [0, 1, 2, ... 22, 23, 24]
labels = [f'{h:02d}:00' for h in hours] # ["00:00", "01:00", ... "23:00", "24:00"]
load = [2000, 2000, 0, 0, 0, 0, 0, 2000, 2000, 2000, 2000, 2000,0,0, 0, 0, 0, 2000, 2000,2000, 2000, 2000, 0,0,0, 0]
temperature = [21, 21.6, 22, 21.3, 20.8, 20.4, 20.1, 20, 20.6, 21.1, 21.5, 21.8, 22, 21.4, 20.9, 20.5, 20.2, 20, 20.7, 21.2, 21.6, 21.9, 22, 21.4, 21]
plt.figure(linewidth=1, figsize=(9, 5))
ax = plt.gca()
ax.plot(hours, load[0:25], color="goldenrod",drawstyle="steps-post", linewidth=3)
ax.plot(hours, load[0:25], color="gold",drawstyle="steps-post", linewidth=3, alpha=.8, label = 'Electrical power') # <- drawstyle argument.
ax.set_xlabel("Time of day", fontsize=16, labelpad=8)
ax.set_ylabel("Electrical power in W", fontsize=14, labelpad=8)
ax.set_xlim(0, 24)
ax.set_ylim(0, 3000)
plt.xticks(hours, labels=labels, rotation=90)
plt.grid(axis='y', alpha=.4)
ax.tick_params(axis='both', which='major', labelsize=14)
ax2 = ax.twinx()
ax2.plot(hours, temperature, color="red", linewidth=3, label = 'Temperature')
ax2.set_ylabel("Temperature in °C", fontsize=14, labelpad=8)
ax2.set_ylim(20, 22.5)
ax2.tick_params(axis='both', which='major', labelsize=14)
fig = plt.gcf()
fig.legend(loc='center left', bbox_to_anchor=(0.25, 1.03), fontsize=14, ncol=3)
fig.tight_layout()
ax.patch.set_visible(False)
fig.savefig('ControlStrategy_Conventional.png', edgecolor='black', dpi=400, bbox_inches='tight')
plt.show()
Я хочу поменять ось. Таким образом, температура должна отображаться на левой оси, а нагрузка - на правой. Я попытался изменить это, но полученный сюжет выглядел странно. Кто-нибудь может сказать мне, что делать? Буду признателен за каждый комментарий.