1. 函数积分图
import matplotlib.pyplot as plt
import numpy as np
def func(x):
return -(x-2)*(x-8)+40
x=np.linspace(0,10)
y=func(x)
fig,ax=plt.subplots() #用于获取坐标轴
plt.plot(x,y,'r',linewidth=3)
a=2
b=8
ax.set_xticks([a,b]) #在坐标轴上加刻度
ax.set_yticks([])
ax.set_xticklabels(['$a$','$b$'])
plt.figtext(0.9,0.1,'$x$')
plt.figtext(0.1,0.9,'$y$')
ax.text(3,35,r'$\int_a^b [(-x-2)*(x-8)+40 ]d(x)$')
plt.ylim(ymin=25)
plt.show()
2. 散点图以及看数据的分布
x=np.random.randn(200)
y=x+np.random.randn(200)*0.5
margin_border=0.1
width=0.6
margin_between&#