python使用matplotlib繪制折線圖的示例代碼
示例代碼如下:
#!/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默認(rèn)為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') #不支持中文# 設(shè)置坐標(biāo)軸的labelax1.set_xlabel('ax1 - X')ax1.set_ylabel('ax1 - Y')# 設(shè)置刻度#ax1.set_xticks([1,2,3,4,5])#ax1.set_yticks([10,20,30,40,50])# 設(shè)置刻度label#ax1.set_xticklabels(['one','two','three','four','five']) # one對(duì)應(yīng)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設(shè)置線條粗細(xì),linestyle設(shè)置線條樣式,marker設(shè)置數(shù)據(jù)點(diǎn)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 居中;...)# 注釋,比如說明最高點(diǎn)# xy指定最高點(diǎn),xytext指定注釋位置arrowprops = {'arrowstyle': '->','color':'red'} #設(shè)置箭頭ax1.annotate('max',xy=(np.pi/2,1),xytext=(np.pi/2+0.5,1),arrowprops=arrowprops)plt.show()
效果如下
以上就是python使用matplotlib繪制折線圖的示例代碼的詳細(xì)內(nèi)容,更多關(guān)于python matplotlib繪制折線圖的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向2. asp(vbs)Rs.Open和Conn.Execute的詳解和區(qū)別及&H0001的說明3. CSS hack用法案例詳解4. PHP設(shè)計(jì)模式中工廠模式深入詳解5. 用css截取字符的幾種方法詳解(css排版隱藏溢出文本)6. ASP+ajax實(shí)現(xiàn)頂一下、踩一下同支持與反對(duì)的實(shí)現(xiàn)代碼7. .NET中l(wèi)ambda表達(dá)式合并問題及解決方法8. ThinkPHP5實(shí)現(xiàn)JWT Token認(rèn)證的過程(親測可用)9. asp中response.write("中文")或者js中文亂碼問題10. JSP數(shù)據(jù)交互實(shí)現(xiàn)過程解析
