其他分享
首页 > 其他分享> > 笔记3 3.matplotlib设置坐标轴

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

请添加图片描述

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

请添加图片描述

标签:plot,plt,color,笔记,坐标轴,matplotlib,y1,y2,linestyle
来源: https://blog.csdn.net/weixin_44632711/article/details/121221162