简体   繁体   English

Python图形绘制

[英]Python Graphic Draw

tdondur x coordinate, y coordinate s.but i can't it. tdondur x坐标,y坐标s。但是我不能。 if you can help. 如果可以的话 Thank you all in advance. 谢谢大家。 now only drawn tdondur value. 现在只绘制tdondur值。 how to plot the value of s. 如何绘制s的值。

from math import e, exp,pow 
import pylab
from gaussxw import gaussxwab

Kb=1.3806505*10**-23
V=10**-3
p=6.022*10**28
Qd=428.0


def f(x):
    isisigasi=9*V*p*Kb*(T/Qd)**3
    return(isisigasi*x**4*(exp(x))/(exp(2)-1)**2)

tut=[] 

Tdondur=range(5,501)
tut=[None for T in Tdondur] 

for tsirala, T in enumerate (Tdondur):
    N=50
    a=0
    b=Qd/T
    x,w=gaussxwab(N,a,b)
    s=0.0
    for k in range (N):
        s+=w[k]*f(x[k])    
    print(T,"'in Isı Sığası : ",s)
    print("----------------------------------------------------------")


pylab.plot(Tdondur)
pylab.title('Isı Sığasının Sıcaklığa Göre Değişimi')
pylab.xlabel('Sıcaklık (T)')
pylab.ylabel('Isı Sığası')
pylab.gcf().savefig('isisigasi.png')
pylab.show()

The problem here is that you're calculating a new value for s in each iteration of the loop, but you never save what you calculate. 这里的问题是,您在循环的每次迭代中都为s计算了一个新值,但从未保存过计算的值。 Instead, make an array for s before you enter the loop, and set s[k] within the loop. 相反,请在进入循环之前为s创建一个数组,然后在循环内设置s[k]

from math import e, exp,pow 
import pylab
from gaussxw import gaussxwab

Kb=1.3806505*10**-23
V=10**-3
p=6.022*10**28
Qd=428.0


def f(x):
    isisigasi=9*V*p*Kb*(T/Qd)**3
    return(isisigasi*x**4*(exp(x))/(exp(2)-1)**2)

tut=[] 

Tdondur=range(5,501)
tut=[None for T in Tdondur] 

s = [0. for i in Tdondur]  # initialize s before entering the loop
for tsirala, T in enumerate (Tdondur):
    N=50
    a=0
    b=Qd/T
    x,w=gaussxwab(N,a,b)
    for k in range (N):
        s[k]+=w[k]*f(x[k])    # work on the values within the loop

pylab.plot(Tdondur, s)
#s_np = pylab.array(s)
#pylab.plot(Tdondur, pylab.log10(s_np))
pylab.title('title')
pylab.xlabel('T')
pylab.ylabel('Y')
#pylab.gcf().savefig('')
pylab.show()

Here's the result (note that the x-axis is magnified): 结果如下(请注意,x轴被放大了):

在此处输入图片说明

Typically for data like this you would want to plot the log of the data, and to do that, uncomment the two lines after that read: 通常,对于这样的数据,您可能希望绘制数据的log ,然后在读取后取消注释两行:

s_np = pylab.array(s)
pylab.plot(pylab.log10(s_np))

(Note that the above lines are using numpy, which is imported with pylab, and is easier than list comprehensions for this type of problem.) (请注意,以上几行使用的是numpy,它是与pylab一起导入的,比这种类型的问题的列表理解要容易得多。)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM