在python自帶編輯器IDLE中,新建腳本如作圖.py
綠園網站制作公司哪家好,找創新互聯公司!從網頁設計、網站建設、微信開發、APP開發、響應式網站等網站項目制作,到程序開發,運營維護。創新互聯公司于2013年創立到現在10年的時間,我們擁有了豐富的建站經驗和運維經驗,來保證我們的工作的順利進行。專注于網站建設就選創新互聯公司。
導入需要的模塊
import numpy as np
import scipy as sp
import pylab as pl
2
輸入代碼
x=np.linspace(0,4*np.pi,100)
pl.plot(x,pl.sin(x))
pl.show()
3
執行代碼,按F5,可直接顯示圖片
4
幾點說明:
1. 方法linspace(0,4*np.pi,100)表示從0開始,到4*pi結束,生成100個點
2. 方法plot為畫圖函數,相當于plot(x,y),x為橫坐標,y為縱坐標
3.show()為展示出來
希望采納!!
不寫出y=f(x)這樣的表達式,由隱函數的等式直接繪制圖像,以x2+y2+xy=1的圖像為例,使用sympy間接調用matplotlib工具的代碼和該二次曲線圖像如下(注意python里的乘冪符號是**而不是^,還有,python的sympy工具箱的等式不是a==b,而是a-b或者Eq(a,b),這幾點和matlab的區別很大)
直接在命令提示行的里面運行代碼的效果
from sympy import *;
x,y=symbols('x y');
plotting.plot_implicit(x**2+y**2+x*y-1);
用python實現計時器功能,代碼如下:
''' Simple Timing Function.
This function prints out a message with the elapsed time from the
previous call. It works with most Python 2.x platforms. The function
uses a simple trick to store a persistent variable (clock) without
using a global variable.
'''
import time
def dur( op=None, clock=[time.time()] ):
if op != None:
duration = time.time() - clock[0]
print '%s finished. Duration %.6f seconds.' % (op, duration)
clock[0] = time.time()
# Example
if __name__ == '__main__':
import array
dur() # Initialise the timing clock
opt1 = array.array('H')
for i in range(1000):
for n in range(1000):
opt1.append(n)
dur('Array from append')
opt2 = array.array('H')
seq = range(1000)
for i in range(1000):
opt2.extend(seq)
dur('Array from list extend')
opt3 = array.array('H')
seq = array.array('H', range(1000))
for i in range(1000):
opt3.extend(seq)
dur('Array from array extend')
# Output:
# Array from append finished. Duration 0.175320 seconds.
# Array from list extend finished. Duration 0.068974 seconds.
# Array from array extend finished. Duration 0.001394 seconds.
當前題目:python計時函數畫圖的簡單介紹
標題鏈接:http://www.hntjjpw.com/article1/hdhgid.html
成都網站建設公司_創新互聯,為您提供ChatGPT、全網營銷推廣、企業網站制作、自適應網站、網站設計、建站公司
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯