integral_demo.py
来自「非原创。很好的python例子」· Python 代码 · 共 36 行
PY
36 行
#!/usr/bin/env python# implement the example graphs/integral from pyxfrom pylab import *from matplotlib.patches import Polygondef func(x): return (x-3)*(x-5)*(x-7)+85ax = subplot(111)a, b = 2, 9 # integral areax = arange(0, 10, 0.01)y = func(x)plot(x, y, linewidth=1)# make the shaded regionix = arange(a, b, 0.01)iy = func(ix)verts = [(a,0)] + zip(ix,iy) + [(b,0)]poly = Polygon(verts, facecolor=0.8, edgecolor='k')ax.add_patch(poly)text(0.5 * (a + b), 30, r"$\int_a^b f(x)\rm{d}x$", horizontalalignment='center', fontsize=20)axis([0,10, 0, 180])figtext(0.9, 0.05, 'x')figtext(0.1, 0.9, 'y')ax.set_xticks((a,b))ax.set_xticklabels(('a','b'))ax.set_yticks([])#savefig('integral_demo')show()
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?