python 實(shí)現(xiàn)將多條曲線畫在一幅圖上的方法
更新時(shí)間:2019年07月07日 14:04:56 作者:諦聽-
今天小編就為大家分享一篇python 實(shí)現(xiàn)將多條曲線畫在一幅圖上的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
如下所示:
# -*- 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)將多條曲線畫在一幅圖上的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
pandas之分組groupby()的使用整理與總結(jié)
這篇文章主要介紹了pandas之分組groupby()的使用整理與總結(jié),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-06-06pytest?用例執(zhí)行失敗后其他不再執(zhí)行
本文主要介紹了pytest?用例執(zhí)行失敗后其他不再執(zhí)行,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02python的命名規(guī)則知識(shí)點(diǎn)總結(jié)
在本篇文章里小編給大家分享的是關(guān)于python的命名規(guī)則知識(shí)點(diǎn)總結(jié),有需要的朋友們可以參考下。2019-10-10Python的進(jìn)制轉(zhuǎn)換和ASCLL轉(zhuǎn)換你了解嗎
這篇文章主要為大家詳細(xì)介紹了Python的進(jìn)制轉(zhuǎn)換和ASCLL轉(zhuǎn)換,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助2022-02-02Pytorch實(shí)現(xiàn)網(wǎng)絡(luò)部分層的固定不進(jìn)行回傳更新問(wèn)題及思路詳解
這篇文章主要介紹了Pytorch實(shí)現(xiàn)網(wǎng)絡(luò)部分層的固定不進(jìn)行回傳更新,實(shí)現(xiàn)思路就是利用tensor的requires_grad,每一個(gè)tensor都有自己的requires_grad成員,值只能為True和False,具體內(nèi)容詳情跟隨小編一起看看吧2021-08-08