Python Forum
Variables will not plot in subplot
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Variables will not plot in subplot
#1
The assignment requires us to make two subplots of the same graph with one having a certain x-axis index and the other having a smaller index. I have gotten the subplots to show up and the associated titles for the graph, but I am unsure why it will not plot the variables I have put in for a.plot(xi, factor, 'b-') and b.plot(xi, factor, 'g-'). Here is the full code. The plot should be pulling values from those variables under the def function at the top (I think). Unfortunately, I do not know how to attach a copy of the plot that is resulting from this as it has no URL in python or if I save it so unless I can be informed the code is all I have. Please let me know what is missing so that I can plot these two graphs. Thank you.

import numpy as np
import matplotlib.pyplot as plt

# undamped and damped natural frequencies
def natural_f_T(m,k,xi):
    wn = np.sqrt(k/m)
    Tn = 2 * np.pi/ wn
    if xi > 0.0:
        factor = np.sqrt(1-xi**2)
        wd = wn * factor
        Td = 2 * np.pi/ wd
    elif xi <= 0.0:
            wd = wn
            Td = Tn
    return wn, Tn, wd, Td, factor

#________________________________________________________________
# specified problem input -- structure
m  = 2.0       # mass, kip-s2/in
k  = 40.0      # stiffness, kips/in
xi = 0.01      # critical damping ratio

# SDOF natural frequencies & periods
wn, Tn, wd, Td, factor = natural_f_T(m,k,xi)
c_critical = 2.0 *m *wn
c          = c_critical * xi

#________________________________________________________________
# output
n =3
print('\n')
print('SDOF natural frequencies & periods')
print('    wn: ', np.round(wn,n),'rad/s')
print('    Tn: ', np.round(Tn,n),'s')
print('    wd: ', np.round(wd,n),'rad/s')
print('    Td: ', np.round(Td,n),'s')
print('  diff: ', np.round((1-factor)*100,n),'%')

# Plots of Damped/Undamped Natural Frequencies

fig, (a, b) = plt.subplots(2)
fig.suptitle('Ratio of Damped to Undamped Natural Frequencies')
plt.xlabel('critical damping ratio')
L=plt.ylabel('Damped/Undamped Natural Frequency')
L.set_position((L.get_position()[0],1))
L.set_verticalalignment('center')
a.plot(xi, factor, 'b-')
b.plot(xi, factor, 'g-')
a.grid()
b.grid()
plt.show()
Reply


Forum Jump:

User Panel Messages

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