Apr-02-2024, 08:56 PM
(Apr-02-2024, 04:20 PM)deanhystad Wrote: Check out secondary axis
https://matplotlib.org/stable/gallery/su..._axis.html
Thank you Dean, subplots did the trick! I did the below standalone code as an experiment and it's doing exactly what I wanted it to, now I just need to adapt it for my application.
import matplotlib.pyplot as plt import numpy as np # Sample data Time = np.arange(1, 61) # 1 to 60 seconds A = np.linspace(60, -50, 60) # A series B = np.linspace(285, 295, 60) # B series # Create the plot fig, ax1 = plt.subplots() # Plot A on the primary y-axis color = 'tab:red' ax1.set_xlabel('Time (s)') ax1.set_ylabel('A', color=color) ax1.plot(Time, A, color=color) ax1.tick_params(axis='y', labelcolor=color) ax1.set_ylim([-100, 100]) # Set y-axis limits for A ax1.grid(True) # Create a secondary y-axis for B ax2 = ax1.twinx() color = 'tab:blue' ax2.set_ylabel('B', color=color) ax2.plot(Time, B, color=color) ax2.tick_params(axis='y', labelcolor=color) ax2.set_ylim([285, 295]) # Set y-axis limits for B # Show the plot plt.title('Comparison of A vs. Time and B vs. Time with Different Scales') plt.show()