3_x、y轴设置到原点、x=-1的画法
from numpy import * import matplotlib.pyplot as plt x = linspace(-5, 5) x3 = linspace(-1, -1) y3 = linspace(-10, 10) y1 = x * 2 y2 = x ** 2 + 1 plt.xlim(-5, 5) plt.ylim(-10, 10) ax = plt.gca() ax.spines['top'].set_color('none') ax.spines['right'].set_color('none') ax.spines['bottom'].set_position(('data', 0)) ax.spines['left'].set_position(('data', 0)) # plt.figure(num=6,) plt.plot(x, y1 + y2, 'purple', linewidth='1.0') plt.plot(x3, y3, linestyle='--') plt.show()
通过设置上边框,右边框的'data'值为0
ax = plt.gca() # gca =get current axis 整个figure系统
ax.spines['top'].set_position(('data',0))
ax.spines['right'].set_position(('data',0))
将左面与下面的边框设置为none,隐藏起来,但是发现刻度孤零零的
ax.spines['left'].set_color('none')
ax.spines['bottom'].set_color('none')
改进:
ax = plt.gca()
ax.spines['top'].set_color('none')
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position(('data',0))
ax.spines['left'].set_position(('data',0))