python 實(shí)現(xiàn)將多條曲線畫在一幅圖上的方法
如下所示:
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 07 09:17:40 2018
@author: yjp
"""
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
y0 = []
y1 = []
y2 = []
y3 = []
y4 = []
f = open("y0.txt")
lines = f.readlines()
for li in lines:
y0.append(li)
f = open("y1.txt")
lines = f.readlines()
for li in lines:
y1.append(li)
f = open("y2.txt")
lines = f.readlines()
for li in lines:
y2.append(li)
f = open("y3.txt")
lines = f.readlines()
for li in lines:
y3.append(li)
f = open("y4.txt")
lines = f.readlines()
for li in lines:
y4.append(li)
font1 = {'family' : 'Times New Roman',
'weight' : 'normal',
'size' : 9,
}
font2 = {'family' : 'Times New Roman',
'weight' : 'normal',
'size' : 14,
}
figsize = 8, 9
plt.subplots(figsize=figsize) # 設(shè)定整張圖片大小
ax1 = plt.subplot(4, 1, 1)
ax1.yaxis.set_major_locator(MultipleLocator(15)) # 設(shè)定y軸刻度間距
#第一條線
x = range(0, len(y0))
plt.plot(x, y0, color='black', label='$DT$', linewidth=0.8) # 繪制,指定顏色、標(biāo)簽、線寬,標(biāo)簽采用latex格式
plt.ylim(-90, -20) # 設(shè)定y軸范圍
hl=plt.legend(loc='upper right', prop=font1, frameon=False) # 繪制圖例,指定圖例位置
#set(hl,'Box','off');
#第二條曲線
x = range(0, len(y1))
plt.plot(x, y1, color='red', label='$M_1$', linewidth=0.8)
plt.legend(loc='upper right', prop=font1, frameon=False) # 繪制圖例,指定圖例位置
plt.xticks([]) # 去掉x坐標(biāo)軸刻度
plt.xlim(0, 580) # 設(shè)定x軸范圍
ax2 = plt.subplot(4, 1, 2)
ax2.yaxis.set_major_locator(MultipleLocator(15))
x = range(0, len(y0))
plt.plot(x, y0, color='black', label='$DT$', linewidth=0.8)
plt.ylim(-90, -20)
hl=plt.legend(loc='upper right', prop=font1, frameon=False)
#set(hl,'Box','off');
x = range(0, len(y2))
plt.plot(x, y2, color='red', label='$M_2$', linewidth=0.8)
plt.legend(loc='upper right', prop=font1, frameon=False)
plt.ylabel("strength/dBm", font2)
plt.xticks([])
plt.xlim(0, 580)
ax3 = plt.subplot(4, 1, 3)
ax3.yaxis.set_major_locator(MultipleLocator(15))
x = range(0, len(y0))
plt.plot(x, y0, color='black', label='$DT$', linewidth=0.8)
hl=plt.legend(loc='upper right', prop=font1, frameon=False)
#set(hl,'Box','off');
plt.ylim(-90, -20)
x = range(0, len(y3))
plt.plot(x, y3, color='red', label='$M_3$', linewidth=0.8)
plt.legend(loc='upper right', prop=font1, frameon=False)
plt.xticks([])
plt.xlim(0, 580)
ax4 = plt.subplot(4, 1, 4)
ax4.yaxis.set_major_locator(MultipleLocator(15))
ax4.xaxis.set_major_locator(MultipleLocator(50))
x = range(0, len(y0))
plt.plot(x, y0, color='black', label='$DT$', linewidth=0.8)
plt.ylim(-90, -20)
hl=plt.legend(loc='upper right', prop=font1, frameon=False)
#set(hl,'Box','off');
x = range(0, len(y4))
plt.plot(x, y4, color='red', label='$M_4$', linewidth=0.8)
plt.legend(loc='upper right', prop=font1, frameon=False)
plt.xlabel("index of grids in path", font2)
plt.xlim(0, 580)
plt.savefig("1.png", dpi=600))
plt.show()

以上這篇python 實(shí)現(xiàn)將多條曲線畫在一幅圖上的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python趣味挑戰(zhàn)之用pygame實(shí)現(xiàn)簡單的金幣旋轉(zhuǎn)效果
今天教大家怎么用pygame實(shí)現(xiàn)簡單的金幣旋轉(zhuǎn)效果,文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)python的小伙伴們很有幫助,需要的朋友可以參考下2021-05-05
Python matplotlib生成圖片背景透明的示例代碼
這篇文章主要介紹了Python matplotlib生成圖片背景透明的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08
Python 按比例獲取樣本數(shù)據(jù)或執(zhí)行任務(wù)的實(shí)現(xiàn)代碼
這篇文章主要介紹了Python 按比例獲取樣本數(shù)據(jù)或執(zhí)行任務(wù),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-12-12
Django框架中render_to_response()函數(shù)的使用方法
這篇文章主要介紹了Django框架中render_to_response()函數(shù)的使用方法,注意范例中該方法的參數(shù)的使用,需要的朋友可以參考下2015-07-07
Python 使用type來定義類的實(shí)現(xiàn)
今天小編就為大家分享一篇Python 使用type來定義類的實(shí)現(xiàn),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-11-11
Pygame游戲開發(fā)之太空射擊實(shí)戰(zhàn)子彈與碰撞處理篇
相信大多數(shù)8090后都玩過太空射擊游戲,在過去游戲不多的年代太空射擊自然屬于經(jīng)典好玩的一款了,今天我們來自己動(dòng)手實(shí)現(xiàn)它,在編寫學(xué)習(xí)中回顧過往展望未來,下面開始講解子彈與碰撞處理,在本課中,我們將添加玩家與敵人之間的碰撞,以及添加供玩家射擊的子彈2022-08-08
如何使Python中的print()語句運(yùn)行結(jié)果不換行
這篇文章主要介紹了如何使Python中的print()顯示當(dāng)前語句后不換行,print() 是一個(gè)常用函數(shù),但是每次,print()語句顯示后都會(huì)換行,本問我們就來節(jié)日如何使print()顯示當(dāng)前語句后不換行,需要的朋友可以參考一下2022-03-03
Python?opencv應(yīng)用實(shí)現(xiàn)圖片切分操作示例
這篇文章主要為大家介紹了Python?opencv應(yīng)用實(shí)現(xiàn)圖片切分的操作示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06

