《Python 数学编程》心得 2

数据可视化

1

列表[];元组()

a=[1,4,6,8,5]

a.append(1)

a=[1,4,6,8,5,1]

for index,item in a:

    print(index,item)

2

标签、坐标

matplotlib

from pylab import plot,show

plot(x,y)

show()


plot(x,y,marker='o')

plot(y,marker='o')

x=range(12)

plot(x,y1,y2)

from pylab import legend()

legend([label 1,label]) 

from pylab import title,xlabel,ylabel

3

非交互

'''
 simple plot using pyplot
'''

import matplotlib.pyplot
def:
    x=[1,2,3,4]
    y=[2,4,6]
    matplotlib.pyplot.plot(x,y)
    matplotlib.pyplot.show()

'''
abbre
'''

import matplotlib.pyplot as plt
def plot1():
x=[1,2,3,]
y=[2,4,6]
plt.plot(x,y)
plt.show()

4设置坐标轴

from pylab import axis
axis(ymin=0)
axis(0,20,0,20)

 

5保存

 import matplotlib.pyplot as plt
x=[1,2,3]
y=[4,5,9]
plt.plot(x,y,marker='o')
plt.show()
plt.savefig('C:\\graph.png')

6练习

1)反比例函数

import matplotlib.pyplot  as plt
x=range(1,13)
a=[]
for i in x:
    y=1.0/i
    a.append(y)
# print(a)
plt.plot(x,a,marker='o')
plt.title('inverse function')
plt.show()
plt.savefig('F:\\python_program\\savefig_inverse')

2)抛物线运动

from matplotlib import pyplot as plt
import math


g= 9.8
u=[]
theta=[]


def draw(x,y):
        plt.plot(x,y,marker='o')
        plt.title('motion')
        plt.xlabel('x')
        plt.ylabel('y')

def point(u, theta,time):
        x=[]
        y=[]
        t=0.0
        while (t<time):
            x.append(u*math.cos(theta)*t)
            y.append(u*math.sin(theta)*t-0.5*g*t**2)
            t=t+0.001
            draw(x,y)


try:

    while(1):
            c=float(input("please enter u :"))
            u.append(c)
            if ' '==input():
                 break

    
    while(1):
            d=float(input("please enter theta:"))
            d=math.radians(d)
            theta.append(d)
            if ' '==input():
                break

except ValueError:
    print('invalid input')
else:
    
#print(u)
#print(theta)

    amount=len(u)
    for i in range(amount):
        flight_time=  u[i]*math.sin(theta[i])*2/g
        point(u[i],theta[i],flight_time)       
    plt.show()

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值