1

I have recently started using python scripting, but have come across a problem when trying to plot a simple graph. It is supposed to produce a Mohr's Circle, but I am definitely missing something. This is the script I have at the moment: Any help would be greatly appreciated!

import math
import numpy as np
import matplotlib.pyplot as plt
%pylab inline

# max = maximum principal stress
# min = minimum principal stress
# x_norm = normal stress in x-direction
# y_norm = normal stress in y-direction
# t = shear stress

x_norm = -60
y_norm = 50
t = 50

R = math.sqrt(((x_norm - y_norm)/2)**2 + t**2)
print R

max = (x_norm + y_norm)/2 + R
min = (x_norm + y_norm)/2 - R
print max
print min

theta = 0.5 * math.atan((2*t)/(x_norm - y_norm))
print theta

aver = (x_norm + y_norm)/2
print aver

x = (min, max, x_norm, y_norm)
y = (math.sqrt(((x_norm - y_norm)/2)**2 + t**2))
plt.subplot(1,2,1)
plt.plot(x,y)
plt.show()

I have tried changing it, but get an error on the last part.

import math
import numpy as np
import matplotlib.pyplot as plt
%pylab inline

# max = maximum principal stress
# min = minimum principal stress
# x_norm = normal stress in x-direction
# y_norm = normal stress in y-direction
# t = shear stress

x_norm = -60
y_norm = 50
t = 50

R = math.sqrt(((x_norm - y_norm)/2)**2 + t**2)
print R

max = (x_norm + y_norm)/2 + R
min = (x_norm + y_norm)/2 - R
print max
print min

theta = 0.5 * math.atan((2*t)/(x_norm - y_norm))
print theta

aver = (x_norm + y_norm)/2
print aver

def circle(x_norm, y_norm, t):
    x = (min, max, x_norm, y_norm)
    y = (math.sqrt(((x_norm - y_norm)/2)**2 + t**2))
    plt.subplot(1,2,1)
    plt.plot(x,y)
    plt.show()

circle(rad,x,y,np.linspace(-100,100,500))
print("Done")



NameError                                 Traceback (most recent call last)
<ipython-input-5-0b893be1e1e8> in <module>()
     35     plt.show()
     36 
---> 37 circle(rad,x,y,np.linspace(-100,100,500))
     38 print("Done")

NameError: name 'x' is not defined
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Chris
  • 21
  • 2

1 Answers1

0

The problem is that you x has dimension 4 and y is dimension 1. In order to use plt.plot you would have to provide the actual points to plot the circles.

There is an easier way to plot circles and here is a thread about it: plot a circle with pyplot? It shows how to draw circles using pyplot.

Community
  • 1
  • 1
pbc1303
  • 142
  • 9