久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

python使用matplotlib繪制折線圖的示例代碼

瀏覽:2日期:2022-07-10 11:52:52

示例代碼如下:

#!/usr/bin/python#-*- coding: utf-8 -*-import matplotlib.pyplot as plt# figsize - 圖像尺寸(figsize=(10,10))# facecolor - 背景色(facecolor='blue')# dpi - 分辨率(dpi=72)fig = plt.figure(figsize=(10,10),facecolor='blue') #figsize默認為4,4(圖像尺寸)ax1 = fig.add_subplot(1,1,1) # 行 列 位置#ax2 = fig.add_subplot(2,1,2)#ax = fig.add_subplot(1,1,1)ax1.set_title('title') #不支持中文# 設置坐標軸的labelax1.set_xlabel('ax1 - X')ax1.set_ylabel('ax1 - Y')# 設置刻度#ax1.set_xticks([1,2,3,4,5])#ax1.set_yticks([10,20,30,40,50])# 設置刻度label#ax1.set_xticklabels(['one','two','three','four','five']) # one對應1# 繪制折線圖x = [1,2,3,4,5]y = [80,3,4,5,1]#生成正弦波曲線import numpy as npx = np.linspace(0,np.pi * 2,20)y = np.sin(x)#生成余弦波曲線y2 = np.cos(x)#ax1.plot(x,y,x,y2) #在一張圖中放置兩條曲線# 使用圖例# linewidth設置線條粗細,linestyle設置線條樣式,marker設置數據點ax1.plot(x,y, label = 'SIN',color='y',linewidth=3,linestyle='--',marker='o')ax1.plot(x,y2,label= 'COS',color='r')ax1.legend(loc='best') # 使用圖例 #best為最佳位置 (upper left 左上;center 居中;...)# 注釋,比如說明最高點# xy指定最高點,xytext指定注釋位置arrowprops = {'arrowstyle': '->','color':'red'} #設置箭頭ax1.annotate('max',xy=(np.pi/2,1),xytext=(np.pi/2+0.5,1),arrowprops=arrowprops)plt.show()

效果如下

python使用matplotlib繪制折線圖的示例代碼

以上就是python使用matplotlib繪制折線圖的示例代碼的詳細內容,更多關于python matplotlib繪制折線圖的資料請關注好吧啦網其它相關文章!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 蓬莱市| 大余县| 葫芦岛市| 海阳市| 丽水市| 伊宁市| 开鲁县| 疏附县| 康乐县| 隆子县| 呼伦贝尔市| 鹤庆县| 南平市| 南宫市| 成都市| 南京市| 舟曲县| 嘉兴市| 蓬安县| 永修县| 昌吉市| 通化市| 清镇市| 北宁市| 博罗县| 梁河县| 江北区| 伽师县| 罗平县| 滦平县| 南和县| 汉中市| 新泰市| 师宗县| 榆中县| 洛扎县| 河南省| 修武县| 平远县| 深泽县| 饶河县|