当前位置:Gxlcms > Python > python如何设置曲线样式

python如何设置曲线样式

时间:2021-07-01 10:21:17 帮助过:182人阅读

python设置曲线样式的方法:1、对坐标系使用一系列的setter方法;2、对线使用一系列的setter方法,代码为【lines = plt.plot(x,x,x,2*x,x,x/2)】

相关学习推荐:python教程

python设置曲线样式的方法:

(1)对坐标系使用一系列的setter方法

  1. x = np.linspace(0,100,30) # 0-100要30个
  2. x
  3. axes = plt.subplot() #获取坐标系
  4. axes.plot(x,x,x,2*x,x,x/2) #画三条线
  5. axes.set_title('title') #设置标题
  6. axes.set_facecolor('gray') #设置背景色
  7. axes.set_xlabel('x') #设置X轴标签
  8. axes.set_ylabel('y') #设置Y轴标签

在这里插入图片描述

(2)对线使用一系列的setter方法

plt.plot()方法返回一个包含所有线的列表

设置每一个线需要获取该线对象

  1. x = np.linspace(0,100,30) # 0-100要30个
  2. x
  3. lines = plt.plot(x,x,x,2*x,x,x/2) #返回一个包含所有线的列表对象
  4. lines[0].set_linewidth(5) #设置第一条线的宽度
  5. lines[1].set_linestyle(':') #设置第二条线的样式
  6. lines[2].set_color('y') #设置第三条先线的颜色

想了解更多相关学习,敬请关注php培训栏目!

以上就是python如何设置曲线样式的详细内容,更多请关注gxlcms其它相关文章!

人气教程排行