2_设置坐标轴

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties  # 解决汉字显示出错

font_set = FontProperties(fname=r'c:\windows\fonts\simsun.ttc', size=15)

x = np.linspace(-2, 2)  # 定义域x的取值范围
y1 = x * 2  # 表达式
y2 = x ** 2 + 1

plt.figure(num=6)   # 标题为 figure 6
plt.xlim(-2, 2)  # x轴坐标的取值区间
plt.ylim(-3, 5)  # y轴坐标的取值区间
plt.xlabel('一元二次方程', fontproperties=font_set)  # 'Text' object has no property 'FontProperties' 这里是fontproperties ,
# 不是FontProperties
plt.ylabel('y轴', fontproperties=font_set)  # 这里是fontproperties ,不是FontProperties
new_xticks = np.linspace(-2,2,5)
new_yticks = np.linspace(-2,10,5)
print(new_xticks)
plt.xticks(new_xticks)  # 设置x轴坐标点
plt.yticks(new_yticks)  # 设置y轴坐标点

plt.plot(x, y1 + y2, 'purple', linestyle='--', linewidth='2.0')  # 绘制图像,颜色, 线型,线宽
plt.show()  # 显示图像

  

posted @ 2023-04-03 06:43  scholar-for-ever  阅读(50)  评论(0编辑  收藏  举报