Python Forum
Help rendering a pylab plot
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help rendering a pylab plot
#1
Hi,

I'm just learning Python and I'm wondering if someone could help me get the chart to render properly in the following code, i.e. plot the sequence of data points. I have put print statements so I can see if the calculations are correct which they are.

Thanks

from pylab import *

# Returns the summer tterature of seawater (in degrees Celsius) according to Mackenzie’s model.
def some_function(ff, dd):
    if dd >=0 and dd <=200:
        tt = (22/-90)*ff+24
    elif dd >=200 and dd <=1000:
        st = (22/-90)*(ff)+24
        gg = (st-2)/-800
        tt = gg*dd+(gg*-1000+2)
    else:
        tt = 2.0
    return tt

ff = float(25)
for dd in range (0, 1200, 100):
    tt1 = some_function(ff, dd)
    plot(dd,tt1)
    print(dd)
    print(tt1)
title("Something")
xlabel("x label")
ylabel("y label")
show()
Reply
#2
Just vectorize your function and plot it:

from pylab import *
 
# Returns the summer tterature of seawater (in degrees Celsius) according to Mackenzie’s model.
@np.vectorize
def some_function(ff, dd):
    if dd >=0 and dd <=200:
        tt = (22/-90)*ff+24
    elif dd >=200 and dd <=1000:
        st = (22/-90)*(ff)+24
        gg = (st-2)/-800
        tt = gg*dd+(gg*-1000+2)
    else:
        tt = 2.0
    return tt
 
ff = float(25)
dd = np.arange(0, 1200, 100)
tt1 = some_function(ff, dd)
plot(dd,tt1)
title("Something")
xlabel("x label")
ylabel("y label")
show()
Reply


Forum Jump:

User Panel Messages

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