def draw_stats(self, vals, vals1, vals2, vals3, vals4, vals5, vals6): self.ax1 = plt.subplot(self.gs[0, 0]) self.ax1.plot(vals) self.ax1.set_xlim(self.xlim) locs = self.ax1.get_xticks() locs[0] = self.xlim[0] locs[-1] = self.xlim[1] self.ax1.set_xticks(locs) self.ax1.use_sticky_edges = False self.ax1.set_title(f'Connected Clients Ratio') self.ax2 = plt.subplot(self.gs[1, 0]) self.ax2.plot(vals1) self.ax2.set_xlim(self.xlim) self.ax2.set_xticks(locs) self.ax2.yaxis.set_major_formatter(FuncFormatter(format_bps)) self.ax2.use_sticky_edges = False self.ax2.set_title('Total Bandwidth Usage') self.ax3 = plt.subplot(self.gs[2, 0]) self.ax3.plot(vals2) self.ax3.set_xlim(self.xlim) self.ax3.set_xticks(locs) self.ax3.use_sticky_edges = False self.ax3.set_title('Bandwidth Usage Ratio in Slices (Averaged)') self.ax4 = plt.subplot(self.gs[3, 0]) self.ax4.plot(vals3) self.ax4.set_xlim(self.xlim) self.ax4.set_xticks(locs) self.ax4.use_sticky_edges = False self.ax4.set_title('Client Count Ratio per Slice') self.ax5 = plt.subplot(self.gs[0, 1]) self.ax5.plot(vals4) self.ax5.set_xlim(self.xlim) self.ax5.set_xticks(locs) self.ax5.use_sticky_edges = False self.ax5.set_title('Coverage Ratio') self.ax6 = plt.subplot(self.gs[1, 1]) self.ax6.plot(vals5) self.ax6.set_xlim(self.xlim) self.ax6.set_xticks(locs) self.ax6.yaxis.set_major_formatter(FormatStrFormatter('%.3f')) self.ax6.use_sticky_edges = False self.ax6.set_title('Block ratio') self.ax7 = plt.subplot(self.gs[2, 1]) self.ax7.plot(vals6) self.ax7.set_xlim(self.xlim) self.ax7.set_xticks(locs) self.ax7.yaxis.set_major_formatter(FormatStrFormatter('%.3f')) self.ax7.use_sticky_edges = False self.ax7.set_title('Handover ratio') self.ax8 = plt.subplot(self.gs[3, 1]) row_labels = [ 'Initial number of clients', 'Average connected clients', 'Average bandwidth usage', 'Average load factor of slices', 'Average coverage ratio', 'Average block ratio', 'Average handover ratio', ] l, r = self.xlim cell_text = [ [f'{len(self.clients)}'], [f'{mean(vals[l:r]):.2f}'], [f'{format_bps(mean(vals1[l:r]), return_float=True)}'], [f'{mean(vals2[l:r]):.2f}'], [f'{mean(vals4[l:r]):.2f}'], [f'{mean(vals5[l:r]):.4f}'], [f'{mean(vals6[l:r]):.4f}'], ] self.ax8.axis('off') self.ax8.axis('tight') self.ax8.tick_params(axis='x', which='major', pad=15) self.ax8.table(cellText=cell_text, rowLabels=row_labels, colWidths=[0.35, 0.2], loc='center right') plt.tight_layout() 更改为只输出其中的第一行第一列的图片
时间: 2024-02-29 07:53:20 浏览: 146
r_ieee_vals_.rar_John A
抱歉,这段代码是用来绘制多张子图并将它们组合成一个大图的,不太适合只输出其中的一张子图。如果您只需要输出其中的一张子图,需要对代码进行相应修改,只绘制需要的子图并将其保存即可。例如,如果只需要输出第一行第一列的子图,可以将其余子图的代码注释掉,然后在最后加上保存图片的代码,比如:
```
def draw_stats(self, vals):
self.ax1 = plt.subplot(1, 1, 1)
self.ax1.plot(vals)
self.ax1.set_xlim(self.xlim)
locs = self.ax1.get_xticks()
locs[0] = self.xlim[0]
locs[-1] = self.xlim[1]
self.ax1.set_xticks(locs)
self.ax1.use_sticky_edges = False
self.ax1.set_title(f'Connected Clients Ratio')
plt.savefig('output.png', dpi=300)
```
这样,该函数将只绘制一个包含第一行第一列子图的图片,并将其保存为 'output.png' 文件。
阅读全文