Issue
I have a function:
def tacoma(dt=1, cromer=True):
..........
..........
return times, theta, displacement
That returns 3 arrays of time, theta and y. What I would like to do is plot two graphs, one showing how theta varies with times, and the other how displacement varies with times, (the length of all of the arrays is the same).
I do not now how to best do this, is there a way I can access times, theta, displacement individually when I call a function?
Solution
Just assign your function's output to variables and use them with matplotlib
.
Here is a quick example:
import matplotlib.pyplot as plt
def tacoma(dt=1, cromer=True):
# this is just a dummy example
times = np.linspace(0, 10, 50)
theta = np.sin(times)
displacement = times**2-dt*times+1
return times, theta, displacement
f, (ax1, ax2) = plt.subplots(nrows=2, sharex=True)
times, th, dis = tacoma()
ax1.plot(times, th)
ax2.plot(times, dis)
ax1.set_title('theta')
ax2.set_title('displacement')
Output:
Answered By - mozway
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.