Hello
I'm relatively new to Python and am not sure how to best display multiple plots in Spyder.
The code below always displays the last plot (each single one works - tested by putting the last one(s) in '''...'''). Can somebody please help me with this?
My Code:
I'm relatively new to Python and am not sure how to best display multiple plots in Spyder.
The code below always displays the last plot (each single one works - tested by putting the last one(s) in '''...'''). Can somebody please help me with this?
My Code:
# pip install control
import numpy as np
import control
import matplotlib.pyplot as plt
from control.matlab import *
# 4s+1
# ---------
# 2s^2+5s-2
num = np.array([4, 1])
den = np.array([2, 5, -2])
# Transfer Function
H = control.tf(num, den)
print('H(s) =', H)
# Zeros
z = control.zero(H)
print('z =', z)
# Poles
p = control.pole(H)
print('p =', p)
# P-Z Map-------------------------------------- 1st plot
control.pzmap(H)
# Bode Plot------------------------------------ 2nd plot
mag, phase, omega = control.bode(H)
# Step Response-------------------------------- 3rd plot
t, y = control.step_response(H)
plt.plot(t, y)
plt.title("Step Response")
plt.grid()
# lsim------------------------------------------ 4th plot
t = np.arange(0, 20, 0.01)
w0 = 3
u = np.cos(w0*t)
yout, T, xout = lsim(H, u, t, X0=0.0)
plt.plot(t, yout)
plt.grid()
plt.show()
Larz60+ write Feb-04-2023, 10:28 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
I added the tags for you this time. Please use on future posts. Thank you.
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
I added the tags for you this time. Please use on future posts. Thank you.
