import matplotlib.pyplot as plt
squ=[]
x=[x for x in range(9)]
for y in range(9):
y2=y*y
squ.append(y2)
plt.plot(x,squ)
plt.show()
import matplotlib.pyplot as plt
squ=[]
x=[x for x in range(9)]
for y in range(9):
y2=y*y
squ.append(y2)
plt.plot(x,squ)
plt.axis([0,8,0,70]) #設定x y 軸的最小及最大的刻度 以list表示
plt.grid() #設定 格線
plt.show()
import matplotlib.pyplot as plt
squ=[]
x=[x for x in range(9)]
for y in range(9):
y2=y*y
squ.append(y2)
plt.plot(x,squ,lw=10) #lw=設定線條寬度
plt.axis([0,8,0,70]) #設定x y 軸的最小及最大的刻度 以list表示
plt.grid() #設定 格線
plt.title("test")
plt.xlabel("values")
plt.ylabel("平方值") #中文出不來
plt.show()
import matplotlib.pyplot as plt
squ=[]
x=[x for x in range(9)]
for y in range(9):
y2=y*y
squ.append(y2)
#把第二數據的y值 設定為費式數列
def fibo(n):
if n == 0:
return 0;
elif n == 1:
return 1;
return fibo(n-1) + fibo(n-2)
fibo1=[]
for i in range(9):
fibosi=fibo(i)
fibo1.append(fibosi)
#plt.plot(x,squ,lw=10) #lw=設定線條寬度
plt.plot(x,squ,x,fibo1) #兩組數據
plt.axis([0,8,0,70]) #設定x y 軸的最小及最大的刻度 以list表示
plt.grid() #設定 格線
plt.title("test")
plt.xlabel("values")
plt.ylabel("平方值") #中文出不來
plt.show()
=========將繪製的圖存成 test.jpg
import matplotlib.pyplot as plt
squ=[]
x=[x for x in range(9)]
for y in range(9):
y2=y*y
squ.append(y2)
#把第二數據的y值 設定為費式數列
def fibo(n):
if n == 0:
return 0;
elif n == 1:
return 1;
return fibo(n-1) + fibo(n-2)
fibo1=[]
for i in range(9):
fibosi=fibo(i)
fibo1.append(fibosi)
#plt.plot(x,squ,lw=10) #lw=設定線條寬度
plt.plot(x,squ,x,fibo1) #兩組數據
plt.axis([0,8,0,70]) #設定x y 軸的最小及最大的刻度 以list表示
plt.grid() #設定 格線
plt.title("test")
plt.xlabel("values")
plt.ylabel("平方值") #中文出不來
plt.savefig("test.jpg") #將繪製的圖存成 test.jpg
plt.show()
======== 使用 matplotlib 內的image 函數 把圖讀出來
import matplotlib.pyplot as plt
import matplotlib.image as img
pic=img.imread("test.jpg") #使用 img.imread()把圖讀出來 叫做pic
plt.imshow(pic) #使用 plot.imshow() 把叫做 pic show出來
plt.show()
====使用 matplotlib 的scatter 畫 圖
import matplotlib.pyplot as plt
x=[x for x in range(9)]
square=[]
for y in range(9):
y2=x[y]*x[y]
square.append(y2)
plt.scatter(x,square)
plt.show()
===========繪制三角函數圖
import matplotlib.pyplot as plt import numpy as np xpt=np.linspace(0,10,500) ypts=np.sin(xpt) yptc=np.cos(xpt) plt.plot(xpt,ypts,color="y",label="sin") plt.plot(xpt,yptc,color="r",label="cos") plt.legend() plt.show()
沒有留言:
張貼留言