Python | 使用matplotlib.pyplot创建线图
Problem statement: Write a program in python (using matplotlib.pyplot) to create a line plot.
問題陳述:用python編寫程序(使用matplotlib.pyplot)以創建線圖。
Program:
程序:
import matplotlib.pyplot as pltx = [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
總結
以上是生活随笔為你收集整理的Python | 使用matplotlib.pyplot创建线图的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: a90j哪个usb是3.0的
- 下一篇: 百雀羚多少钱啊?