您好,登錄后才能下訂單哦!
如下所示:
# -*- 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)容了,希望能給大家一個參考,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。