由于比较简单,只靠代码的注释就差不多了:
1 #导入需要的库import numpy as np 2 import matplotlib.pyplot as plt 3 4 #定义变量和函数x = np.arange(-100, 100, 0.001) 5 y = x**3/(3*x+1) 6 7 #画图准备plt.figure() 8 plt.plot(x, y, linestyle='--', color='blue') 9 10 #设置x和y的范围plt.xlim((-0.8, 0.8)) 11 plt.ylim((-0.8, 0.8)) 12 13 #美化图片ax = plt.gca() 14 ax.spines['right'].set_color('none') 15 ax.spines['top'].set_color('none') 16 ax.xaxis.set_ticks_position('bottom') 17 ax.yaxis.set_ticks_position('left') 18 ax.spines['bottom'].set_position(('data', 0)) 19 ax.spines['left'].set_position(('data', 0)) 20 21 #显示图像plt.show()
结果:
好了,赶紧try it yourself!
标签:0.8,set,python,spines,plt,模块,position,ax,numpy From: https://www.cnblogs.com/guochaoxxl/p/16984267.html