Mechpy Tutorials

a mechanical engineering toolbox

source code - https://github.com/nagordon/mechpy
documentation - https://nagordon.github.io/mechpy/web/


Neal Gordon
2017-02-20


Sundries

this is just various codes for doing silly things with data processing and engineering stuff

Convert a string of numbers to a list or array


In [3]:
import numpy as np
y = '''62606.53409
59989.34659
62848.01136
80912.28693
79218.03977
81242.1875
59387.27273
73027.5974
69470.69805
66843.99351
82758.44156
81647.72727
77519.96753'''
y = [float(x) for x in np.array(y.replace('\n',',').split(','))]
print(y, end=" ")


[62606.53409, 59989.34659, 62848.01136, 80912.28693, 79218.03977, 81242.1875, 59387.27273, 73027.5974, 69470.69805, 66843.99351, 82758.44156, 81647.72727, 77519.96753] 

Ascii Plot


In [2]:
from sympy import symbols, exp, pi, cos
from sympy.plotting import textplot
x = symbols('x')
textplot( exp(-x) * cos(2*pi*x)  ,0,5, 75,20)


      1 |                                                                            
        |  .                                                                         
        |                                                                            
        |                                                                            
        |                                                                            
        |   .                                                                        
        |                                                                            
        |               ..                                                           
        |              .  \                                                          
0.19330 | ---.-------------.---------------------------------------------------------
        |             .                ...                                           
        |                   .        ..   ..         ....                            
        |                    .      /       ..    ...    ............................
        |     .      .             /          ....                                   
        |                     ..  /                                                  
        |           .           ..                                                   
        |      .                                                                     
        |          .                                                                 
        |                                                                            
-0.6133 |       ...                                                                  
          0                                2.5                                  5

another example of an Ascii Plot


In [ ]:
# This is the same example as in the scitools.aplotter doc string

import numpy as np
x = np.linspace(0, 5, 81)
#y = np.exp(-0.5*x**2)*np.cos(np.pi*x)
y=np.exp(-x)*np.cos(2*np.pi*x)
from scitools.aplotter import plot
plot(x, y)

plot(x, y, draw_axes=False)

# Plot symbols (the dot argument) at data points
plot(x, y, plot_slope=False)

# Drop axis labels
plot(x, y, plot_labels=False)

plot(x, y, dot='o', plot_slope=False)

# Store plot in a string
p = plot(x, y, output=str)
print(p)