import numpy as np
import matplotlib.pyplot as plt
'''
numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None):
start就是开始的数字
stop就是结束的数字
num就是返回的数量
endpoint是一个bool型变量,如果是True 那么会出现最后的stop
'''
x = np.linspace(-6, 6, 50)
y = x ** 2
plt.plot(x, y, color='red') # 线条为红色
# 获取当前的坐标轴
ax = plt.gca()
# 设置右边框和上边框
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
# 设置x坐标轴为下边框
ax.xaxis.set_ticks_position('bottom')
# 设置y坐标轴为左边框
ax.yaxis.set_ticks_position('left')
# 设置x轴、y轴在(0,0)的位置
ax.spines['bottom'].set_position(('data', 0))
ax.spines['left'].set_position(('data', 0))
plt.show()
matplotlib设置曲线图x轴和y轴位置
最新推荐文章于 2022-10-05 03:31:28 发布