I have a time-series dataset. I want to plot the data i.e. current, voltage, and power each on the y-axis. I tried to do it with the following code but facing some errors (Image link attached).
Need help with the following:
- adjusting scale of each y-axis
- setting color of each y-axis
- setting legends
Any other suggestions for improvement of code or alternative solutions are most welcome.
fig, ax1 = plt.subplots(figsize=(12,10))
ax2 = ax1.twinx()
ax3 = ax1.twinx()
ax1.set_ylim(0, 10)
ax2.set_ylim(0, 100)
ax3.set_ylim(0, 1000)
ax1.set_ylabel("Output Current")
ax2.set_ylabel("Output Voltage")
ax3.set_ylabel("Output Power")
color1 = plt.cm.viridis(0)
color2 = plt.cm.viridis(0.5)
color3 = plt.cm.viridis(.9)
ax1 = output_params.Output_Voltage.plot(color=color1, label= 'Output Current')
ax2 = output_params.Output_Current.plot(color=color2, label='Output Voltage')
ax3 = output_params.Output_Power.plot(color=color3, label='Output Power')
lns = [ax1, ax2, ax3]
ax1.legend(handles=lns, loc='best')
# right, left, top, bottom
ax3.spines['right'].set_position(('outward', 60))
ax1.yaxis.label.set_color(ax1.get_color())
ax2.yaxis.label.set_color(ax2.get_color())
ax3.yaxis.label.set_color(ax3.get_color())
# Adjust spacings w.r.t. figsize
fig.tight_layout()