1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > python十字坐标轴绘制_matplotlib画十字坐标图

python十字坐标轴绘制_matplotlib画十字坐标图

时间:2020-07-20 00:34:14

相关推荐

python十字坐标轴绘制_matplotlib画十字坐标图

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()

画图()

示例结果:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。