# -*- coding: utf-8 -*-
import matplotlib
#https://blog.csdn.net/zjjtilm/article/details/79106348
#导入包
import matplotlib.pyplot as plt
import numpy as np
import math
# 确定坐标轴
plt.xlim((-2, 2))
plt.ylim((-0.5, 1))
# 确定函数的x,y点
# 原函数
x1 = np.linspace(-3,3.5,100)
def y1(x1):
y1 = np.sin(x1 - 2)*np.sin(x1 - 2)*np.exp( -1 * x1 * x1)
return y1
# plot为绘制图像的函数,label为标记
plt.plot(x1, y1(x1), 'r-',linewidth=1,label='f(x)')
# 在图上添加文字注释
plt.text(-1,y1(0),'f(x)=sin(x1-2)*sin(x1-2)*exp(-1*x1*x1)',size=13)
# 将标记绘制图例
plt.legend(['f(x)'], loc = 'lower right')
plt.show()
结果