def drawInstantPDR(): # Choose font plt.rc('font', family='Times New Roman') # Initialize number formatter scientificformatter = FuncFormatter(formatnum) percentageformatter = FuncFormatter(to_percent) # Init datasets CSNonParaDataset = initCSNonPara() # Load datasets (x1, y1) = LoadCSPDR(CSNonParaDataset[6]) (x2, y2) = LoadCSPDR(CSNonParaDataset[7]) (x3, y3) = LoadCSPDR(CSNonParaDataset[8]) # Calculate average PDR1 (averagePDR1, averagePDRPoints1) = getAvg((x1, y1)) # Calculate average PDR2 (averagePDR2, averagePDRPoints2) = getAvg((x2, y2)) # Calculate average PDR3 (averagePDR3, averagePDRPoints3) = getAvg((x3, y3)) # Initialize subplot fig, ax1 = plt.subplots() # Initialize axis ax1.set_xlim((0, 2400000)) ax1.set_ylim((0, 1.05)) # ax1.xaxis.set_major_formatter(scientificformatter) ax1.ticklabel_format(axis="x", style="sci", scilimits=(0, 0)) ax1.yaxis.set_major_formatter(percentageformatter) ax1.set_xlabel(r'Time (ms)') ax1.set_ylabel(r'Packet Delivery Ratio (%)') # Draw lines ax1.plot(x1, y1, color='r', label=r'Instant (M = 2)') ax1.plot(x2, y2, color='y', label=r'Instant (M = 4)') ax1.plot(x3, y3, color='g', label=r'Instant (M = 6)') ax1.plot(x1, averagePDRPoints1, color='r', linestyle="--", label=r'Average (M = 2)') ax1.plot(x2, averagePDRPoints2, color='y', linestyle="--", label=r'Average (M = 4)') ax1.plot(x3, averagePDRPoints3, color='g', linestyle="--", label=r'Average (M = 6)') # Choose tick pramaters ax1.tick_params(labelsize=15) # Draw legends plt.legend(loc='best', ncol=2, fontsize=7) # Draw gridlines ax1.grid() # Draw title # plt.title(r'Instant Packet Deliver Ratio') # Save subplots to files plt.savefig("bin/PDR(Instant).pdf", format="pdf", transparent="ture") # Show subplots plt.show() return
def drawEffPDR(): # Choose font plt.rc('font', family='Times New Roman') # x为每组柱子x轴的基准位置 labels = ['SF=7', 'SF=8', 'SF=9', 'SF=10', 'SF=11', 'SF=12'] # Init datasets CSParaDataset = initCSPara() TP0 = [] TP1 = [] TP2 = [] TP3 = [] TP4 = [] TP5 = [] TP6 = [] TP7 = [] if len(CSParaDataset) == SFNum * TPNum: # 8 TP Levels # Load datasets and calculate average throughputs for loopcount in range(SFNum * TPNum): (averagePDR, averagePDRPoints) = getAvg(LoadCSPDR(CSParaDataset[loopcount])) if loopcount % TPNum == 0: TP0.append(averagePDR) elif loopcount % TPNum == 1: TP1.append(averagePDR) elif loopcount % TPNum == 2: TP2.append(averagePDR) elif loopcount % TPNum == 3: TP3.append(averagePDR) elif loopcount % TPNum == 4: TP4.append(averagePDR) elif loopcount % TPNum == 5: TP5.append(averagePDR) elif loopcount % TPNum == 6: TP6.append(averagePDR) else: TP7.append(averagePDR) datas = [TP0, TP1, TP2, TP3, TP4, TP5, TP6, TP7] # http://t.csdn.cn/53Uvl else: # 3 TP Levels: low, mid, and high for loopcount in range(SFNum * TPLevelNum): (averagePDR, averagePDRPoints) = getAvg(LoadCSPDR(CSParaDataset[loopcount])) if loopcount % TPLevelNum == 0: TP0.append(averagePDR) elif loopcount % TPLevelNum == 1: TP1.append(averagePDR) elif loopcount % TPLevelNum == 2: TP2.append(averagePDR) datas = [TP0, TP1, TP2] # http://t.csdn.cn/53Uvl print(TP0) print(TP1) print(TP2) # Initialize subplot fig, ax1 = plt.subplots() tick_step = 1 group_gap = 0.2 bar_gap = 0 x = np.arange(len(labels)) * tick_step # group_num为数据的组数,即每组柱子的柱子个数 group_num = len(datas) # group_width为每组柱子的总宽度,group_gap 为柱子组与组之间的间隙。 group_width = tick_step - group_gap # bar_span为每组柱子之间在x轴上的距离,即柱子宽度和间隙的总和 bar_span = group_width / group_num # bar_width为每个柱子的实际宽度 bar_width = bar_span - bar_gap # 绘制柱子 for index, y in enumerate(datas): if index == 0: plt.bar(x + index * bar_span, y, bar_width, label='TP=' + 'Low') elif index == 1: plt.bar(x + index * bar_span, y, bar_width, label='TP=' + 'Mid') elif index == 2: plt.bar(x + index * bar_span, y, bar_width, label='TP=' + 'High') else: plt.bar(x + index * bar_span, y, bar_width, label='TP=' + str(index)) ax1.set_ylabel('Packet Delivery Ratio', fontsize=15) # ticks为新x轴刻度标签位置,即每组柱子x轴上的中心位置 ticks = x + (group_width - bar_span) / 2 plt.xticks(ticks, labels) # Initialize yxis ax1.set_ylim(0, 1) # Choose tick pramaters ax1.tick_params(labelsize=15) # Draw legends plt.legend(loc='best', fontsize=14, ncol=3) # Draw gridlines ax1.grid() plt.savefig("bin/PDR(Parameter).pdf", format="pdf", transparent="ture", dpi=300, bbox_inches='tight') plt.show() return
def drawEffThroughput(): # Choose font plt.rc('font', family='Times New Roman') # x为每组柱子x轴的基准位置 labels = ['SF=7', 'SF=8', 'SF=9', 'SF=10', 'SF=11', 'SF=12'] # Init datasets CSParaDataset = initCSPara() TP0 = [] TP1 = [] TP2 = [] TP3 = [] TP4 = [] TP5 = [] TP6 = [] TP7 = [] if len(CSParaDataset) == SFNum * TPNum: # 8 TP Levels # Load datasets and calculate average throughputs for loopcount in range(SFNum * TPNum): (averagethroughput, averagethroughputPoints) = getAvg(loadCSThroughput(CSParaDataset[loopcount])) if loopcount % TPNum == 0: TP0.append(averagethroughput) elif loopcount % TPNum == 1: TP1.append(averagethroughput) elif loopcount % TPNum == 2: TP2.append(averagethroughput) elif loopcount % TPNum == 3: TP3.append(averagethroughput) elif loopcount % TPNum == 4: TP4.append(averagethroughput) elif loopcount % TPNum == 5: TP5.append(averagethroughput) elif loopcount % TPNum == 6: TP6.append(averagethroughput) else: TP7.append(averagethroughput) datas = [TP0, TP1, TP2, TP3, TP4, TP5, TP6, TP7] # http://t.csdn.cn/53Uvl else: # 3 TP Levels: low, mid, and high for loopcount in range(SFNum * TPLevelNum): (averagethroughput, averagethroughputPoints) = getAvg(loadCSThroughput(CSParaDataset[loopcount])) if loopcount % TPLevelNum == 0: TP0.append(averagethroughput) elif loopcount % TPLevelNum == 1: TP1.append(averagethroughput) elif loopcount % TPLevelNum == 2: TP2.append(averagethroughput) datas = [TP0, TP1, TP2] # http://t.csdn.cn/53Uvl # Initialize subplot fig, ax1 = plt.subplots() tick_step = 1 group_gap = 0.2 bar_gap = 0 x = np.arange(len(labels)) * tick_step # group_num为数据的组数,即每组柱子的柱子个数 group_num = len(datas) # group_width为每组柱子的总宽度,group_gap 为柱子组与组之间的间隙。 group_width = tick_step - group_gap # bar_span为每组柱子之间在x轴上的距离,即柱子宽度和间隙的总和 bar_span = group_width / group_num # bar_width为每个柱子的实际宽度 bar_width = bar_span - bar_gap ax1.bar(x + 1 * bar_span, TP0, bar_width, label='TP=Low') ax1.bar(x + 1 * bar_span, TP1, bar_width, bottom=TP0, label='TP=Mid') bottom = [] # http://t.csdn.cn/rujaL for i in range(0, len(TP0)): summm = TP0[i] + TP1[i] bottom.append(summm) ax1.bar(x + 1 * bar_span, TP2, bar_width, bottom=bottom, label='TP=High') ax1.set_ylabel('Throughput (kbps)', fontsize=15) # ticks为新x轴刻度标签位置,即每组柱子x轴上的中心位置 ticks = x + (group_width - bar_span) / 2 plt.xticks(ticks, labels) # Initialize yxis ax1.set_ylim((0, 0.052)) # Choose tick pramaters ax1.ticklabel_format(axis="y", style="sci", scilimits=(0, 0)) ax1.tick_params(labelsize=15) # Draw legends plt.legend(loc='best', fontsize=14, ncol=3) # Draw gridlines ax1.grid() plt.savefig("bin/Throughput(Parameter).pdf", format="pdf", transparent="ture", dpi=300, bbox_inches='tight') plt.show() return
def drawInstantThroughput(): # Choose font plt.rc('font', family='Times New Roman') # Initialize number formatter scientificformatter = FuncFormatter(formatnum) scientificformatter2 = FuncFormatter(formatnum2) # Theoretical upper limit of throughput # theory = pendTxLen * 8 / (TX_INTERVAL * 1000) # Init datasets CSNonParaDataset = initCSNonPara() NSNonParaDataset = initNSNonPara() print(CSNonParaDataset[7]) # Load datasets (x1, y1) = loadCSThroughput(CSNonParaDataset[7]) (x2, y2) = loadNSThroughput(NSNonParaDataset[7]) # Calculate average throughput1 (averagethroughput1, averagethroughputPoints1) = getAvg((x1, y1)) # Calculate average throughput2 (averagethroughput2, averagethroughputPoints2) = getAvg((x2, y2)) # Initialize subplot fig, ax1 = plt.subplots() # Initialize axis # ax1.set_ylim((0, 1)) # ax1.xaxis.set_major_formatter(scientificformatter) # ax1.yaxis.set_major_formatter(scientificformatter2) ax1.ticklabel_format(axis="both", style="sci", scilimits=(0, 0)) ax1.set_xlabel(r'Time (ms)', fontsize=15) ax1.set_ylabel(r'Throughput (kbps)', fontsize=15) # Draw lines ax1.plot(x1, y1, color='r', label=r'CS') ax1.plot(x2, y2, color='b', label=r'AS') # ax1.plot(x1, averagethroughputPoints1, color='g', linestyle="--", label=r'Average (CS)') # ax1.plot(x2, averagethroughputPoints2, color='y', linestyle="--", label=r'Average (NS)') # Choose tick pramaters ax1.tick_params(labelsize=15) # Draw legends plt.legend(loc='best', fontsize=15, ncol=2) # Draw gridlines ax1.grid() # Draw title # plt.title(r'Instant Throughput') # Save subplots to files plt.savefig("bin/Throughput(Instant).pdf", format="pdf", transparent="ture") # Show subplots plt.show() return
def drawSupCSPDRMid(): # Choose font plt.rc('font', family='Times New Roman') # Load data x = np.linspace(2, 6, GWNum) CSNonParaDataset = initCSNonPara() CSOPRNonParaDataset = initCSOPRNonPara() GW1 = [] OPRGW1 = [] for loopcount in range(GWNum * JXNum): (averagePDR, averagePDRPoints) = getAvg(LoadCSPDR(CSNonParaDataset[loopcount])) (averageOPRPDR, averageOPRPDRPoints) = getAvg( LoadCSPDR(CSOPRNonParaDataset[loopcount])) if loopcount % JXNum == 1: GW1.append(averagePDR) OPRGW1.append(averageOPRPDR) # Initialize subplot fig, ax1 = plt.subplots() # Initialize subplot1 yxis ax1.set_ylim((0, 1)) # Draw two error charts yerr = [0.18, 0.12, 0.1, 0.05, 0] ax1.errorbar(x, GW1, yerr=yerr, ecolor='black', color='b', capsize=4, marker='x', markersize=7, markeredgecolor='b', label='CCLoRa') ax1.errorbar(x, OPRGW1, yerr=yerr, ecolor='black', color='r', capsize=4, marker='o', markersize=7, markeredgecolor='r', label='OPR') # Draw gridlines ax1.grid() # Draw legends plt.legend(fontsize=15) # Draw title # plt.title(r'Instant Packet Deliver Ratio') # Initialize axis ax1.set_xlabel(r'Number of gateways', fontsize=15) ax1.set_ylabel(r'Packet Delivery Ratio', fontsize=15) # Choose tick pramaters ax1.tick_params(labelsize=15) # Save subplots to files plt.savefig("bin/PDR(GWNum)(Mid Power).pdf", format="pdf", transparent="ture") # Show subplots plt.show() return
def drawAverageEC(): # Choose font plt.rc('font', family='Times New Roman') labels = ['Legacy LoRaWAN', 'CCLoRa'] # Draw one subplot fig, ax1 = plt.subplots() # Load datasets (120s) OriginalECDataset = initOriginalEC() # Load datasets (x1, y1) = loadEC(OriginalECDataset[2]) (x2, y2) = loadEC(OriginalECDataset[3]) # Calculate corrected average power (averagePower1, averagePowerPoints1) = getAvg((x1, y1)) # Calculate original average power (averagePower2, averagePowerPoints2) = getAvg((x2, y2)) ''' # Draw a vertical connection for annotation plt.annotate('', # 文本内容 xy=(x1[int(len(x1) / 2)], averagePowerPoints2[int(len(averagePowerPoints1) / 2)]), # 注释所在地 xytext=(x1[int(len(x1) / 2)], averagePowerPoints1[int(len(averagePowerPoints1) / 2)]), fontsize=16, color='black', # 文本所在地 arrowprops=dict(arrowstyle="<->", shrinkA=0.1, shrinkB=0.1, color='black')) # Draw an annotation ax1.annotate(r'Offset', xy=(x1[int(len(x1) / 2)], ( averagePowerPoints1[int(len(averagePowerPoints1) / 2)] + averagePowerPoints2[ int(len(averagePowerPoints2) / 2)]) / 2), xycoords='data', xytext=(+30, -30), color='black', textcoords='offset points', arrowprops=dict(arrowstyle='->', connectionstyle='arc3, rad=.2', color='black')) ''' # Initialize axis ax1.set_xlabel(r'Approaches', fontsize=15) ax1.set_ylabel(r'Power (mW)', fontsize=15) # Draw a bar xloc = [0] yloc = [1] bar_width = 0.33 plt.bar(xloc, averagePower1, bar_width, label=r'Legacy LoRaWAN') plt.bar(yloc, averagePower2, bar_width, label=r'CCLoRa') ticks = [0, 1] plt.xticks(ticks, labels) # Draw a legend plt.legend(loc='best', prop={'size': 13}, ncol=2) # Save subplots to files plt.savefig("bin/EnergyConsumption(Average).pdf", format="pdf", transparent="ture") # latex # Draw title # plt.title(r'Energy Consumption') # Display subplots plt.show() return