Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Multiple Plots in Spyder
#1
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:
# 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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to loop through code to plot seaborn line plots across multiple subplots eyavuz21 0 1,660 Dec-05-2022, 10:46 AM
Last Post: eyavuz21
  Multiple user defined plots with secondary axes using for loop maltp 1 1,442 Apr-30-2022, 10:19 AM
Last Post: maltp
  Subplot - Plotting 4 plots on the same row Menthix 1 1,417 Nov-07-2021, 09:03 PM
Last Post: deanhystad
  How can I scroll over my data points when creating plots in Python? (I'm using Spyder moose 0 1,603 Nov-02-2020, 07:18 AM
Last Post: moose
  Sharing X Axis in Sub plots JoeDainton123 1 2,180 Aug-22-2020, 04:11 AM
Last Post: deanhystad
  Help With Sub Plots JoeDainton123 0 1,699 Aug-20-2020, 10:48 PM
Last Post: JoeDainton123
  Group scatter plots Mekala 0 1,643 Jul-23-2020, 02:18 PM
Last Post: Mekala
  How to plot multiple scatter plots in seaborn vikola 2 6,482 Jul-14-2019, 10:30 AM
Last Post: vikola
  Saving multiple plots as pdf mohd_umair 0 3,339 Apr-28-2019, 01:21 PM
Last Post: mohd_umair
  Can't locate plots package BobLoblaw 12 10,932 Oct-04-2017, 11:56 PM
Last Post: BobLoblaw

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020