2016-12-27 76 views
1

我要繪製線條和點在接下來的代碼中的問題,當我使用plt.plot與X4,Y4只是讓我點,我想知道是什麼問題。我正在使用python 3.52和wingware python IDE 101 5.1。matplotlib只顯示點

import matplotlib.pyplot as plt 
from itertools import chain 



od = float(input("Ingrese el diametro externo: ")) 
id = float(input("Ingrese el diametro interno: ")) 
Yp = int(input("Ingrese la cedencia de la tuberia: ")) 
DF2 = float(input("Ingrese factor de diseño triaxial: ")) 

area=((od**2)-(id**2))*0.7854 
Fy=area*Yp 
Fy=int(Fy) 

Fy2=-(1.16*Fy) 
Fy2=int(Fy2) 
Fy3=(1.16*Fy) 
Fy3=int(Fy3) 
t = ((od - id)/2) 



s= (od/t) 
s=float(s) 

ca=Fy2 


c_com=range(Fy2,0,2000) 
c_ten=range(0,Fy3,2000) 


for ca in chain(c_com,c_ten): 


    ca1 = (ca/area) 
    BB = (ca1/Yp) 
    cc = ((1 - (0.75 * ((BB) ** (2))))) 
    if cc<0: 
     cc = 0 
    d = (((cc) **(0.5)) - (0.5 * BB)) 
    d1 = (((cc) **(0.5)) + (0.5 * BB)) 
    Ype= d * (Yp) 
    Ype1=d1 * (Yp) 

    a = 2.8762 + (0.10679* (0.00001)*Ype)+(0.21301 * (0.0000000001) * ((Ype) ** (2)))- (0.53132 * (1E-16) * ((Ype) **(3))) 

    b = 0.026233 + (0.50609 * (0.000001) * Ype) 
    c = -465.93 + (0.030867 * Ype) - (0.10483 * (0.0000001) * ((Ype) ** (2))) + (0.36989 * (0.0000000000001) * ((Ype) ** (3))) 
    if c < -20000 : 
     break 
    O = (b/a) 
    f = ((46.95 * 1000000) * (((3 * O)/(2 + O)) ** (3)))/((Ype * (((3 * O)/(2 + O) - O))) * ((1 - ((3 * O)/(2 + O)))) ** (2)) 

    g = f * O 


    L = (c/ Ype) 
    s1 = ((((a - 2) + (8 * (b+ L))) ** (0.5)) + (a - 2))/(2 * (b + L)) 
    s1=abs(s1) 
    s2 = (Ype * (a - f))/(c + (Ype * (b - g))) 
    s2=float(s2) 
    s3 = (2 + (b/a))/(3 * b/a) 
    s3=float(s3) 


    Pc1 = 2 * Ype * ((s - 1)/(s * s)) 
    Pc2 = (Ype * ((a/s) - b)) - c 
    Pc3 = (Ype * ((f/s) - g)) 
    Pc4 = (46.95 * 1000000)/(s * ((s - 1) ** 2)) 


    Pc=0 
    Pc=int(Pc) 


    if s<s1 : 
     Pc= Pc1 

    elif s1<s<s2: 
     Pc = Pc2 
    elif s2 < s < s3: 
     Pc= Pc3 
    elif s>s3: 
     Pc = Pc4 

    Pe=0 
    Pe = (0.875 * 2 * Ype1 * t)/od 
    Pe=int(Pe) 
    Pc=int(Pc) 
    if 0<ca<Fy-7000: 
     coo=((-Pc/1)) 
     caa=(ca) 
     x4=(caa,Fy) 
     y4=(coo,0) 
     plt.plot(x4,y4,"ro-",markersize=3) 
     plt.show() 


    if ca==0: 
     co=str((-Pc)) 
     Pb=str((Pe)) 
     x3=[0,-Fy,-Fy,-Fy,0,Fy,Fy] 
     y3=[co,co,0,Pb,Pb,Pb,0] 
     plt.plot(x3,y3,color='y',linewidth=2) 
+0

是證明問題的必要數學嗎?把這個提取到一個MCVE:http://stackoverflow.com/help/mcve –

回答

1

移動plt.showif子句外面,並把它的代碼的最末端,或在for循環結束。

當你調用plt.plot,一個新的情節構造,但沒有顯示,所以沒有圖像繪製,但結構已創建。您可以使用新數據多次撥打plt.plot,這些數據會累積起來,當您撥打show時,會在同一幅圖像上繪製多幅圖。

+0

謝謝你的回答,我試着你說的,但是這個情節讓我看到了許多行,不僅僅是一行所有的點。 –

+0

@MIGUELTORO,然後嘗試將呼叫移至循環外的'show'。 – ForceBru

+0

我做到了,但沒有任何變化 –