函数积分图
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
def func(x):
return -(x-2)*(x-8)+40
x = np.linspace(0,10)
y=func(x)
5
fig,ax = plt.subplots()
plt.plot(x,y,'r',linewidth=2)
a=2
b=9
ax.set_xticks([a,b])
ax.set_xticklabels(['$a$','$b$'])
ix = np.linspace(a,b)
iy = func(ix)
#拼接坐标对
ixy = zip(ix,iy)
verts = [(a,0)]+list(ixy)+[(b,0)]
poly = Polygon(verts,facecolor = '0.9',edgecolor='0.9')
ax.add_patch(poly)
ax.set_yticks([])
plt.figtext(0.9,0.1,'$x$')
plt.figtext(0.1,0.9,'$y$')
x_math = (a+b)*0.15
y_math = 35
plt.text(x_math,y_math,r'$\int_a^b(-(x-2)*(x-8)+40)dx$',fontsize=15)
plt.show()
散点——条形图
plt.style.use('ggplot')
x = np.random.randn(200)
y=x+np.random.randn(200)*0.5
margin_border = 0.1
width =0.6
height = 0.2
margin_between=0.02
left_s = margin_border
bottom_s = margin_border
height_s= width
width_s = width
x
left_x = margin_border
bottom_x = margin_border+width+margin_between
height_x= height
width_x = width
r
left_y = margin_border+width+margin_between
bottom_y = margin_border
height_y = width
width_y = height
x
plt.figure(1,figsize=(10,10))
rect_s=[left_s,bottom_s,height_s,width_s]
rect_x=[left_y,bottom_y,height_y,width_y]
rect_y=[left_x,bottom_x,height_x,width_x]
<Figure size 720x720 with 0 Axes>
y
axScatter=plt.axes(rect_s)
axHistX=plt.axes(rect_x)
axHistY=plt.axes(rect_y)
绘图实战
最新推荐文章于 2024-06-28 22:13:07 发布