日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python一条竖线_python matplotlib 画一条水平直线遇到的问题

發布時間:2024/9/19 python 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python一条竖线_python matplotlib 画一条水平直线遇到的问题 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

想要的圖像如下:

一開始是這樣畫的:

import numpy as np #使用import導入模塊numpy,并簡寫成np

import matplotlib.pyplot as plt #使用import導入模塊matplotlib.pyplot,并簡寫成plt

plt.figure(figsize=(8,4)) #設置繪圖對象的寬度和高度

t = np.arange(0,1.1,0.1)

theta = 30+15*(t**2)

theta_v = 30*t

theta_accel = 30

plt.plot(t,theta,label="$theta$",color="red",linewidth=2)

plt.plot(t,theta_v,label="$thetaV$",color="green",linewidth=2)

#plt.plot(t,theta_accel,label="$thetaAccel$",color="blue",linewidth=2)

t = np.arange(1,3.1,0.1)

theta = 45+30*(t-1)

theta_v = 30

theta_accel = 0

plt.plot(t,theta,label="$theta$",color="red",linewidth=2)

#plt.plot(t,theta_v,label="$thetaV$",color="green",linewidth=2)

#plt.plot(t,theta_accel,label="$thetaAccel$",color="blue",linewidth=2)

t = np.arange(3,4.1,0.1)

theta = 120-15*((4-t)**2)

theta_v = 30*(4-t)

theta_accel = -30

plt.plot(t,theta,label="$theta$",color="red",linewidth=2)

plt.plot(t,theta_v,label="$thetaV$",color="green",linewidth=2)

#plt.plot(t,theta_accel,label="$thetaAccel$",color="blue")

plt.ylim(-40,200) #使用plt.ylim設置y坐標軸范圍

plt.xlim(-1,5)

plt.xlabel("Time(s)") #用plt.xlabel設置x坐標軸名稱

plt.legend(loc='upper left') #設置圖例位置

plt.grid(True)

plt.show()

#plt.plot(t,theta_accel,label="$thetaAccel$",color="blue",linewidth=2)

可以發現當theta_accel為常數時 plot失效,無法畫出圖像。

因為theta_accel = -30 不含變量t,改為:

theta_accel = -30 +t*0

則函數能夠畫出想要畫的圖像。

修改完,代碼如下:

"""niku 習題5.5"""

import numpy as np #使用import導入模塊numpy,并簡寫成np

import matplotlib.pyplot as plt #使用import導入模塊matplotlib.pyplot,并簡寫成plt

plt.figure(figsize=(8,4)) #設置繪圖對象的寬度和高度

t = np.arange(0,1.1,0.1)

theta = 30+15*(t**2)

theta_v = 30*t

theta_accel = 30+t*0

plt.plot(t,theta,label="$theta$",color="red",linewidth=2)

plt.plot(t,theta_v,label="$thetaV$",color="green",linewidth=2)

plt.plot(t,theta_accel,label="$thetaAccel$",color="b")

t = np.arange(1,3.1,0.1)

theta = 45+30*(t-1)

theta_v = 30+t*0

theta_accel = 0 +t*0

plt.plot(t,theta,label="$theta$",color="red",linewidth=2)

plt.plot(t,theta_v,label="$thetaV$",color="green",linewidth=2)

plt.plot(t,theta_accel,label="$thetaAccel$",color="b",linewidth=2)

t = np.arange(3,4.1,0.1)

theta = 120-15*((4-t)**2)

theta_v = 30*(4-t)

theta_accel = -30 +t*0

plt.plot(t,theta,label="$theta$",color="red",linewidth=2)

plt.plot(t,theta_v,label="$thetaV$",color="green",linewidth=2)

plt.plot(t,theta_accel,label="$thetaAccel$",color="b")

plt.ylim(-40,125) #使用plt.ylim設置y坐標軸范圍

plt.xlim(-1,5)

plt.xlabel("Time(s)") #用plt.xlabel設置x坐標軸名稱

'''設置圖例位置'''

#plt.legend(loc='upper right') #設置圖例位置

plt.grid(True)

plt.show()

生成圖像如下:

成功!!!

總結

以上是生活随笔為你收集整理的python一条竖线_python matplotlib 画一条水平直线遇到的问题的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。