2

I have a problem to plot lines and points in the next code, when I use plt.plot with x4,y4 only show me the points, I would like to know what's the problem. I am using python 3.52 and wingware python IDE 101 5.1.

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)
1
  • is all of that math necessary to demonstrate the problem? Distill this down to an MCVE: stackoverflow.com/help/mcve Commented Dec 27, 2016 at 18:11

1 Answer 1

1

Move plt.show outside the if clause and put it at the very end of the code, or at the end of the for loop.

When you call plt.plot, a new plot is constructed, but not shown, so no image is drawn, but the structure is already created. You can call plt.plot many times with new data, which will accumulate and when you call show, will result in many graphs drawn on the same image.

Sign up to request clarification or add additional context in comments.

7 Comments

thanks for your answer, i tried what you said but the plot show me many lines together,no just one line with all the points.
@MIGUELTORO, then try to move the call to show outside the loop.
i did it but nothing change
@MIGUELTORO, can you please show an example output plot?
@MIGUELTORO, this link redirects me to example.com for some reason.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.