首页 > 其他 > 详细

matplotlib学习之函数积分图

时间:2017-10-06 19:55:00      阅读:297      评论:0      收藏:0      [点我收藏+]
# coding:utf-8

import numpy as np
from matplotlib import pyplot as plt
from matplotlib.patches import Polygon

‘‘‘
求函数积分
‘‘‘


def func(x):
    return -(x - 2) * (x - 8) + 40


print(plt.style.available)
plt.style.use("ggplot")

# 绘制曲线
x = np.linspace(0, 10)
y = func(x)
fig, ax = plt.subplots()
plt.plot(x, y, linewidth=2)

# 设置坐标轴
a = 2
b = 9
ax.set_xticks([a, b])  # 设置横坐标2,9
ax.set_yticks([])  # 设置纵坐标为空
ax.set_xticklabels([$a$, $b$])  # 设置横坐标显示为a,b
plt.figtext(0.91, 0.09, $x$)  # 设置坐标轴字母
plt.figtext(0.11, 0.88, $y$)

# 确定多边形
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.5)
ax.add_patch(poly)

# 添加数学公式
x_math = (a + b) * 0.5
y_math = 35
plt.text(x_math, y_math, r$\int_a^b(-(x - 2) * (x - 8) + 40)$, fontsize=13, horizontalalignment=center)

plt.title(functional integration)
plt.show()

技术分享

 

matplotlib学习之函数积分图

原文:http://www.cnblogs.com/jasonhaven/p/7632556.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!