Matplotlib绘制经验
郝伟 2022/0/0

简介

本文将包括大量自绘制的Matplotlib效果图,内容可能是直接的绘制或相关链接。

示例:曲线+散点图

'''
作者:郝伟老师
日期:2021/03/09
描述:使用离散数据绘制曲线和点序列。
历史:
2021/03/09 建立文档
2021/05/17 修改标题
资料:
* matplotlib.pyplot.plot函数官方文档
https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html#matplotlib.pyplot.plot
'''

# 绘制 y = x^x 的在[0, 1] 上的曲线
import matplotlib.pyplot as plt

def f(x):
    return x ** x

section_number=100
section_length=1.0 / section_number
res=0
xs, ys=[], []
for i in range(section_number):
    xi = i * section_length
    yi = f(xi)
    xs.append(xi)
    ys.append(yi)
    res += yi * section_length
    
print('result:', res)    
plt.plot(xs, ys, 'bo--')
plt.show()