Home  >  Article  >  Backend Development  >  How to set curve style in python

How to set curve style in python

coldplay.xixi
coldplay.xixiOriginal
2020-08-27 14:14:263310browse

How to set the curve style in Python: 1. Use a series of setter methods for the coordinate system; 2. Use a series of setter methods for the lines. The code is [lines = plt.plot(x,x,x ,2*x,x,x/2)】

How to set curve style in python

##【

Related learning recommendations:python tutorial

How to set the curve style in python:

(1) Use a series of setter methods on the coordinate system

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

Insert picture description here

(2) Use a series of setter methods for lines

plt.plot()The method returns a list containing all lines

Setting each line requires obtaining the line object

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

If you want to know more about related learning, please pay attention to the

php training column!

The above is the detailed content of How to set curve style in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn