Help rendering a pylab plot - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Help rendering a pylab plot (/thread-18292.html) |
Help rendering a pylab plot - cyberman - May-12-2019 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() RE: Help rendering a pylab plot - scidam - May-15-2019 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() |