最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python編程使用matplotlib繪制動態(tài)圓錐曲線示例

 更新時間:2021年10月19日 11:56:44   作者:微小冷  
這篇文章主要介紹了Python使用matplotlib繪制動態(tài)的圓錐曲線示例實現(xiàn)代碼,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步

作為讓高中生心臟驟停的四個字,對于高考之后的人來說可謂刻骨銘心,所以定義不再贅述,直接擼圖,其標準方程分別為

在這里插入圖片描述

在Python中,繪制動圖需要用到matplotlib中的animation包,其調(diào)用方法以及接下來要用到的參數(shù)為

ani = animation.FuncAnimation(fig, func, frames, interval)

其中fig為繪圖窗口,func為繪圖函數(shù),其返回值為圖像,frames為迭代參數(shù),如果為整型的話,其迭代參數(shù)則為range(frames)。

橢圓

為了繪圖方便,橢圓的參數(shù)方程為

在這里插入圖片描述

在這里插入圖片描述

代碼為:

# 這三個包在后面的程序中不再復述
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
a,b,c = 5,3,4
fig = plt.figure(figsize=(12,9))
ax = fig.add_subplot(autoscale_on=False, 
    xlim=(-a,a),ylim=(-b,b))
ax.grid()
line, = ax.plot([],[],'o-',lw=2)
trace, = ax.plot([],[],'-', lw=1)
theta_text = ax.text(0.02,0.85,'',transform=ax.transAxes)
textTemplate = '''theta = %.1f°\n
lenL = %.1f, lenR = %.1f\n
lenL+lenR = %.1f'''
xs,ys = [], []
def animate(i):
    if(i==0):
        xs.clear()
        ys.clear()
    theta = i*0.04
    x = a*np.cos(theta)
    y = b*np.sin(theta)
    xs.append(x)
    ys.append(y)
    line.set_data([-c,x,c], [0,y,0])
    trace.set_data(xs,ys)
    lenL = np.sqrt((x+c)**2+y**2)
    lenR = np.sqrt((x-c)**2+y**2)
    theta_text.set_text(textTemplate % 
        (180*theta/np.pi, lenL, lenR, lenL+lenR))
    return line, trace, theta_text
ani = animation.FuncAnimation(fig, animate, 157, 
    interval=5, blit=True)
ani.save("ellipse.gif")
plt.show()

雙曲線

雙曲線的參數(shù)方程為

在這里插入圖片描述

設 a = 4 , b = 3 , c = 5 則代碼如下

a,b,c = 4,3,5
fig = plt.figure(figsize=(12,9))
ax = fig.add_subplot(autoscale_on=False, 
    xlim=(-c,16),ylim=(-12,12))
ax.grid()
line, = ax.plot([],[],'o-',lw=2)
trace, = ax.plot([],[],'-', lw=1)
theta_text = ax.text(0.01,0.85,'',
    transform=ax.transAxes)
textTemplate = '''t = %.1f\n
lenL = %.1f, lenR = %.1f\n
lenL-lenR = %.1f'''
xs,ys = [],[]
def animate(t):
    if(t==-3):
        xs.clear()
        ys.clear()
    x = a*np.cosh(t)
    y = b*np.sinh(t)
    xs.append(x)
    ys.append(y)
    line.set_data([-c,x,c], [0,y,0])
    trace.set_data(xs,ys)
    lenL = np.sqrt((x+c)**2+y**2)
    lenR = np.sqrt((x-c)**2+y**2)
    theta_text.set_text(textTemplate % 
        (t, lenL, lenL, lenL-lenR))
    return line, trace, theta_text
frames = np.arange(-3,3,0.05)
ani = animation.FuncAnimation(fig, animate, 
    frames, interval=5, blit=True)
ani.save("hyperbola.gif")

plt.show()

在這里插入圖片描述

拋物線

在這里插入圖片描述

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation
a,b,c = 4,3,5
p = 1
fig = plt.figure(figsize=(12,9))
ax = fig.add_subplot(autoscale_on=False, 
    xlim=(-0.6,4.5),ylim=(-3,3))
ax.grid()
ax.plot([-p/2,-p/2],[-5,5],'-',lw=2)
line, = ax.plot([],[],'o-',lw=2)
trace, = ax.plot([],[],'-', lw=1)
theta_text = ax.text(0.05,0.85,'',
    transform=ax.transAxes)
textTemplate = '''y = %.1f\n
lenL = %.1f, lenF = %.1f\n
lenL-lenF = %.1f'''
xs,ys = [],[]
def animate(y):
    if(y==-3):
        xs.clear()
        ys.clear()
    x = y**2/p/2
    xs.append(x)
    ys.append(y)
    line.set_data([-p,x,p/2], [y,y,0])
    trace.set_data(xs,ys)
    lenL = x+p/2
    lenF = np.sqrt((x-p/2)**2+y**2)
    theta_text.set_text(textTemplate % 
        (y, lenL, lenF, lenL-lenF))
    return line, trace, theta_text
frames = np.arange(-3,3,0.1)
ani = animation.FuncAnimation(fig, animate, 
    frames, interval=5, blit=True)
ani.save("parabola.gif")
plt.show()

在這里插入圖片描述

極坐標方程

圓錐曲線在極坐標系下有相同的表達式,即

在這里插入圖片描述

matplotlib中,極坐標圖像需要通過projection='polar'來標識,其代碼為

p = 2
fig = plt.figure(figsize=(12,9))
ax = fig.add_subplot(autoscale_on=False, projection='polar')
ax.set_rlim(0,8)
trace, = ax.plot([],[],'-', lw=1)
theta_text = ax.text(0.05,0.95,'',transform=ax.transAxes)
textTemplate = 'e = %.1f\n'
theta = np.arange(-3.1,3.2,0.1)
def animate(e):
    rho = p/(1-e*np.cos(theta))
    trace.set_data(theta,rho)
    theta_text.set_text(textTemplate % e)
    return trace, theta_text
frames = np.arange(-2,2,0.1)
ani = animation.FuncAnimation(fig, animate, 
    frames, interval=100, blit=True)
ani.save("polar.gif")
plt.show()

在這里插入圖片描述

以上就是Python使用matplotlib繪制動態(tài)的圓錐曲線示例的詳細內(nèi)容,更多關于matplotlib繪制動態(tài)圓錐曲線的資料請關注腳本之家其它相關文章!

相關文章

  • python字典按照value排序方法

    python字典按照value排序方法

    在本篇文章里小編給各位分享一篇關于python字典按照value排序方法的相關文章,有興趣的朋友們可以學習下。
    2020-12-12
  • pycharm如何使用anaconda中的各種包(操作步驟)

    pycharm如何使用anaconda中的各種包(操作步驟)

    這篇文章主要介紹了pycharm如何使用anaconda中的各種包,本文通過操作步驟給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-07-07
  • Django記錄操作日志與LogEntry的使用詳解

    Django記錄操作日志與LogEntry的使用詳解

    我們既知道如何記錄變更日志,也知道如何獲取變更日志,那么如何才能夠在admin后臺方便地查看操作日志呢?這篇文章主要給大家介紹了關于Django記錄操作日志與LogEntry使用的相關資料,需要的朋友可以參考下
    2022-01-01
  • Python實現(xiàn)貪心算法的示例

    Python實現(xiàn)貪心算法的示例

    這篇文章主要介紹了Python實現(xiàn)貪心算法的示例,幫助大家更好的理解和學習使用python,感興趣的朋友可以了解下
    2021-04-04
  • python的函數(shù)和方法(上)

    python的函數(shù)和方法(上)

    這篇文章主要為大家詳細介紹了python的函數(shù)和方法,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • 詳解利用裝飾器擴展Python計時器

    詳解利用裝飾器擴展Python計時器

    在本文中,云朵君將和大家一起了解裝飾器的工作原理,如何將我們之前定義的定時器類?Timer?擴展為裝飾器,以及如何簡化計時功能,感興趣的可以了解一下
    2022-06-06
  • python中序列的逆序方式

    python中序列的逆序方式

    這篇文章主要介紹了python中序列的逆序方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • Python+Kepler.gl輕松制作酷炫路徑動畫的實現(xiàn)示例

    Python+Kepler.gl輕松制作酷炫路徑動畫的實現(xiàn)示例

    這篇文章主要介紹了Python+Kepler.gl輕松制作酷炫路徑動畫的實,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧現(xiàn)示例
    2020-06-06
  • python判斷所輸入的任意一個正整數(shù)是否為素數(shù)的兩種方法

    python判斷所輸入的任意一個正整數(shù)是否為素數(shù)的兩種方法

    今天小編就為大家分享一篇python判斷所輸入的任意一個正整數(shù)是否為素數(shù)的兩種方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-06-06
  • Django ForeignKey與數(shù)據(jù)庫的FOREIGN KEY約束詳解

    Django ForeignKey與數(shù)據(jù)庫的FOREIGN KEY約束詳解

    這篇文章主要介紹了Django ForeignKey與數(shù)據(jù)庫的FOREIGN KEY約束詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-05-05

最新評論

米泉市| 武定县| 监利县| 华容县| 黄山市| 佳木斯市| 博兴县| 邹城市| 新乐市| 吉林市| 丰都县| 郴州市| 望奎县| 武威市| 长丰县| 临洮县| 滁州市| 庆安县| 峨山| 德阳市| 沾化县| 麻阳| 扎鲁特旗| 莆田市| 牙克石市| 司法| 古丈县| 铜川市| 黄梅县| 六枝特区| 通化县| 澄城县| 宁强县| 合川市| 葫芦岛市| 西峡县| 睢宁县| 扎兰屯市| 建宁县| 巴里| 青铜峡市|