Problem statement: Write a program in python (using matplotlib.pyplot) to create a line plot.
问题陈述:用python编写程序(使用matplotlib.pyplot)以创建线图。
Program:
程序:
import matplotlib.pyplot as plt
x = [1,2,3,4,5,6,7,8,9,10]
y = [3,9,6,12,5,1,10,5,4,9]
plt.plot(x,y, label='lineplots', color='b')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Line Plot')
plt.legend()
plt.show()
Output
输出量
Explanation:
说明:
Python library matplotlib.pyplot is used to draw the above chart. Two random variables x and y are taken with random values. The plot function plots a line plot. The plot function takes 2 arguments i.e. x and y and a label variable gives the label to the plot. To name the axes xlabel and ylabel functions are used and to give the title to the plot the title function is used. To show the legend the legend function is used and finally to show the plot the show functions.
Python库matplotlib.pyplot用于绘制以上图表。 两个随机变量x和y带有随机值。 图函数绘制线图。 plot函数接受2个参数,即x和y,以及一个label变量为该图提供标签。 为了命名轴,使用了xlabel和ylabel函数,并且使用了title函数为绘图赋予标题。 为了显示图例,使用了图例功能,最后使用show函数显示了情节。
翻译自: https://www.includehelp.com/python/create-a-line-plot-using-matplotlib-pyplot.aspx