import matplotlib.pyplot as plt
import numpy as np
def 画图():
#plt.grid() #显示网格
#plt.rcParams['axes.unicode_minus'] = False #可显示负号
plt.title("十字坐标图示")
fig=plt.figure(1,dpi=160)
ax=plt.gca()
#去掉边框
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
#指定x与y轴
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')
#设置x与y轴的位置
ax.spines['bottom'].set_position(('data', 0))
#设置为居中显示: 'center' 代替 ('data', 0)
ax.spines['left'].set_position(('data', 0)) #设置为(0,0)显示
#定义公式
x = np.linspace(-6, 6, 100)
y = np.sin(x+1)-(x-1)
#解释性文字
plt.text(1,4,"y=sin(x+1)-(x-1)")
plt.plot(x,y)
plt.show()
画图()
示例结果: