笔记3 3.matplotlib设置坐标轴

import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-1,1,100)
y1 = 2*x + 1
y2 = x**2

# 范围
plt.xlim((-1,2))
plt.ylim((-2,3))

# xy描述
plt.xlabel('X')
plt.ylabel('Y')

plt.plot(x,y1,color = 'red',linewidth = 1.0,linestyle = '--')
plt.plot(x,y2,color = 'blue',linewidth = 5.0, linestyle = '-')
plt.show()

笔记3 3.matplotlib设置坐标轴

new_ticks = np.linspace(-2,2,11)
print(new_ticks)
[-2.  -1.6 -1.2 -0.8 -0.4  0.   0.4  0.8  1.2  1.6  2. ]
x = np.linspace(-1,1,100)
y1 = 2*x + 1
y2 = x**2

# 范围
plt.xlim((-1,2))
plt.ylim((-2,3))

# xy描述
plt.xlabel('X')
plt.ylabel('Y')

plt.plot(x,y1,color = 'red',linewidth = 1.0,linestyle = '--')
plt.plot(x,y2,color = 'blue',linewidth = 5.0, linestyle = '-')

plt.xticks(new_ticks)
plt.yticks([-1,0,1,2,3],
          ['level1','level2','level3','level4','level5'])
plt.show()

笔记3 3.matplotlib设置坐标轴

上一篇:《机器学习实战》 | 第3章 决策树(含Matplotlib模块介绍)


下一篇:matplotlib以对象方式绘制子图