编写 test_sin_x2.py 如下
# -*- coding: utf-8 -*-
""" 绘制函数 y = sin(x^2) 在 -5<=x<=5 的曲线 """
import numpy as np
from matplotlib import pyplot as plt
# 用于正常显示中文标题,负号
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
x = np.arange(-5., 5., 0.01)
y = np.sin(x**2)
# 可视化
fig = plt.figure()
axes = fig.add_subplot(111)
axes.plot(x, y) # 画曲线
axes.axis('scaled') # 用缩尺制图
#axes.axis('equal')
plt.title('函数 y = sin(x^2) 的曲线')
plt.xlabel('x')
plt.ylabel('y')
plt.xticks(range(-6,7,1), range(-6,7,1))
plt.yticks(range(-2,3,1), range(-2,3,1))
plt.grid()
plt.show()
运行 python test_sin_x2.py

2521

被折叠的 条评论
为什么被折叠?



