第一题:二次函数与反比例函数曲线
import matplotlib.pyplot as plt
import numpy as np
fig,ax = plt.subplots(figsize=(6,8))
plt.rcParams['axes.unicode_minus']=False
plt.ylim(0,1)
plt.subplot(211,title="pingfangquxian",xticks=np.arange(1.0))
plt.rcParams['front.san-serif']=['SimHei']
x=-1
Y=[]
X=[]
while x<=1:
Y.append(x**2)
X.append(x)
x+=0.01
plt.plot(X,Y,marker='.')
plt.subplot(212,title="daoshuquxian",xticks=np.arange(1.0))
plt.ylim(0,10.5)
plt.xlim(0,0.95)
x=0.1
Y=[]
X=[]
while x<=0.9:
t=1/x
Y.append(t)
X.append(x)
x+=0.01
print(x)
print(t)
plt.plot(X,Y,marker='.')
plt.show()
第二题:正弦函数散点曲线
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['front.san-serif']=['SimHei']
#fig,ax =
plt.subplots(figsize=(12,8))
plt.title("Ftriangle")
plt.xlim=(-4,4)
x=np.arange(-np.pi,np.pi,0.05)
y=np.sin(x)
plt.axhline(y=0,c="black")
plt.axvline(x=0,c="black")
plt.scatter(x,y,marker="*")
plt.plot((0,0),color="black")
plt.text(-np.pi,0.1,"-pi")
plt.text(np.pi,0.1,"pi")
plt.text(0.1,1,"Y")
plt.text(3.3,-0.1,"X")
第三题:图像灰度分布直方图
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
im=np.array(Image.open("angle.jpg"))
n=int(im.size/3)
hd=256*[0]
row=im.shape[0]
col=im.shape[1]
for i in range(row):
for j in range(col):
v=im[i,j,0]*0.299+im[i,j,1]*0.587+im[i,j,2]*0.114
hd[int(v)]+=1
#hd[i*col+j]=v
#plt.hist(hd,256,color='k')
bar_width=1
index=range(256)
plt.bar(index,hd,bar_width,alpha=1,color='k')
plt.show()
第四题:
import matplotlib.pyplot as plt
import numpy as np
plt.subplots(nrows=2,ncols=1,figsize=(8,17))
plt.subplots_adjust(hspace=1)
plt.subplot(211,title="rt")
t=0
dx=[]
dy=[]
while t<2*np.pi:
y=(2*np.cos(t)-np.cos(2*t))
x=(2*np.sin(t)-np.sin(2*t))
dx.append(x)
dy.append(y)
t+=0.01
fig1=plt.plot(dx,dy,marker='.')
fig2=plt.subplot(212,title="r")
theta=np.linspace(0.0,2*np.pi,100)
r=1-np.sin(theta)
fig2=plt.polar(theta,r,marker=".")
plt.show()
第五题:
import matplotlib.pyplot as plt
score = [0.1,0.2,0.2,0.05,0.4,0.05]
plt.rcParams['font.sans-serif']=['SimHei']
plt.title("支出比例")
labels = ['学习用品', '日常用品', '伙食费', '通讯费','娱乐费','其他开支']
explode = (0,0,0,0,0.2,0)
plt.axis("equal")
plt.pie(score, explode=explode, labels=labels, autopct='%4.1f%%')
plt.legend(bbox_to_anchor=(1, 0.6))