跟着莫烦python的教程在学,现在把这个知识点记录下来,免得忘记
图像是有四个spine的,分别是top,bottom,left,right
import numpy as np
import matplotlib.pyplot as plt
import math
import pandas as pd
if __name__ == '__main__':
x = np.linspace(-10,20,60)
y = 2*x+1
plt.plot(x,y,'b--',linewidth=1)
# plt.xlim(1,10)
plt.xlabel("x")
plt.ylabel("y = 2*x+1 ")
ax = plt.gca() # gca = get current axis
ax.spines['right'].set_color('None') #将right和top的线条去掉(图上方和右边的边框)
ax.spines['top'].set_color('None')
ax.xaxis.set_ticks_position("bottom") #设置x轴
ax.yaxis.set_ticks_position("left") #设置y轴
ax.spines['bottom'].set_position(('data',0)) #设置x轴位置
ax.spines['left'].set_position(('data', 0))
plt.show()