ha = tight_subplot(4,2,[.05 .1],[.15 .05],[.17 .05]); 图之间的距离] axes(ha(1)); semilogx(f_series, Zdd_m_mag,'r*', f_series1, Zdd_r_mag,'b', 'LineWidth', 1.5) ylabel({'Magnitude';'(dB)'}); set(gca, 'FontSize', figure_FontSize,'XTick',[]); set(get(gca,'YLabel'),'FontSize',figure_FontSize,'Vertical','middle');
时间: 2023-09-16 14:12:04 浏览: 45
这段代码是使用 `tight_subplot` 函数创建一个 4x2 的子图布局,并设置了图之间的距离。然后,通过 `axes(ha(1))` 将当前 axes 设置为第一个子图,接着使用 `semilogx` 绘制了两条曲线,并设置了线宽为 1.5,其中 `f_series` 和 `Zdd_m_mag` 是绘制红色星号的数据,`f_series1` 和 `Zdd_r_mag` 是绘制蓝色线条的数据。
接下来,使用 `ylabel` 设置了纵坐标轴的标签,标签内容为 "Magnitude" 和 "(dB)",并且使用 `set` 函数设置了当前 axes 的字体大小为 `figure_FontSize`,同时将 x 轴的刻度设置为空。最后,使用 `set(get(gca,'YLabel'),'FontSize',figure_FontSize,'Vertical','middle')` 将纵坐标轴标签的字体大小设置为 `figure_FontSize`,并使其垂直居中显示。
相关问题
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')修改为一张张输出图片
好的,你可以将这段代码修改为:
```python
def draw_stats(self, vals, vals1, vals2, vals3, vals4, vals5, vals6, save_path):
fig, axs = plt.subplots(4, 2, figsize=(16, 16))
axs[0, 0].plot(vals)
axs[0, 0].set_xlim(self.xlim)
locs = axs[0, 0].get_xticks()
locs[0] = self.xlim[0]
locs[-1] = self.xlim[1]
axs[0, 0].set_xticks(locs)
axs[0, 0].use_sticky_edges = False
axs[0, 0].set_title(f'Connected Clients Ratio')
axs[1, 0].plot(vals1)
axs[1, 0].set_xlim(self.xlim)
axs[1, 0].set_xticks(locs)
axs[1, 0].yaxis.set_major_formatter(FuncFormatter(format_bps))
axs[1, 0].use_sticky_edges = False
axs[1, 0].set_title('Total Bandwidth Usage')
axs[2, 0].plot(vals2)
axs[2, 0].set_xlim(self.xlim)
axs[2, 0].set_xticks(locs)
axs[2, 0].use_sticky_edges = False
axs[2, 0].set_title('Bandwidth Usage Ratio in Slices (Averaged)')
axs[3, 0].plot(vals3)
axs[3, 0].set_xlim(self.xlim)
axs[3, 0].set_xticks(locs)
axs[3, 0].use_sticky_edges = False
axs[3, 0].set_title('Client Count Ratio per Slice')
axs[0, 1].plot(vals4)
axs[0, 1].set_xlim(self.xlim)
axs[0, 1].set_xticks(locs)
axs[0, 1].use_sticky_edges = False
axs[0, 1].set_title('Coverage Ratio')
axs[1, 1].plot(vals5)
axs[1, 1].set_xlim(self.xlim)
axs[1, 1].set_xticks(locs)
axs[1, 1].yaxis.set_major_formatter(FormatStrFormatter('%.3f'))
axs[1, 1].use_sticky_edges = False
axs[1, 1].set_title('Block ratio')
axs[2, 1].plot(vals6)
axs[2, 1].set_xlim(self.xlim)
axs[2, 1].set_xticks(locs)
axs[2, 1].yaxis.set_major_formatter(FormatStrFormatter('%.3f'))
axs[2, 1].use_sticky_edges = False
axs[2, 1].set_title('Handover ratio')
plt.tight_layout()
plt.savefig(save_path)
plt.show()
```
这样就可以一张张输出图片了,你只需要传入一个保存路径参数 `save_path` 即可。
解释代码import numpy as np import matplotlib.pyplot as plt # plt 用于显示图片 import matplotlib.image as mpimg # mpimg 用于读取图片 fig = plt.figure() #matplotlib只支持PNG图像 lena = mpimg.imread('cat.jpg') lena_r=np.zeros(lena.shape) #0通道 lena_r[:,:,0]=lena[:,:,0] ax1=fig.add_subplot(331) ax1.imshow(lena_r)# 显示R通道 lena_g=np.zeros(lena.shape)#1通道 lena_g[:,:,1]=lena[:,:,1] ax4=fig.add_subplot(334) ax4.imshow(lena_g)# 显示G通道 lena_b=np.zeros(lena.shape)#2通道 lena_b[:,:,2]=lena[:,:,2] ax7=fig.add_subplot(337) ax7.imshow(lena_b)# 显示B通道 img_R = lena_r[:,:,0] R_mean=np.mean(img_R) R_std=np.std(img_R) ax2=fig.add_subplot(332) flatten_r=img_R.flatten() weights = np.ones_like(flatten_r)/float(len(flatten_r)) prob_r,bins_r,_=ax2.hist(flatten_r,bins=10,facecolor='r',weights=weights) img_G = lena_g[:,:,1] G_mean=np.mean(img_G) G_std=np.std(img_G) ax5=fig.add_subplot(335) flatten_g=img_G.flatten() prob_g,bins_g,_=ax5.hist(flatten_g,bins=10,facecolor='g',weights=weights) img_B = lena_b[:,:,2] B_mean=np.mean(img_B) B_std=np.std(img_B) ax8=fig.add_subplot(338) flatten_b=img_B.flatten() prob_b,bins_b,_=ax8.hist(flatten_b,bins=10,facecolor='b',weights=weights) ax3=fig.add_subplot(233) rgb_mean=[R_mean,G_mean,B_mean] x_mlabel=['R_mean','G_mean','B_mean'] bar_width=0.5 bars_mean=ax3.bar(x_mlabel,rgb_mean,width=bar_width) colors=['r','g','b'] for bar,color in zip(bars_mean,colors): bar.set_color(color) ax3.set_title('Mean') ax9 = fig.add_subplot(236) rgb_std =[R_std,G_std,B_std] x_mlabel = ['R_std','G_std','B_std'] bar_width = 0.5 bars_std = ax9.bar(x_mlabel,rgb_std,width = bar_width) colors = ['r','g','b'] for bar,color in zip(bars_std,colors): bar.set_color(color) ax9.set_title('Std') # fig.set_tight_layout(True) plt.show()
这段代码主要是读取一张名为"cat.jpg"的图片,并对其RGB三个通道进行分析和统计。
首先,将原图的RGB三个通道分别提取出来,然后在左上角、左中和左下角用subplot展示三个通道的图像。
接着,分别计算每个通道的像素值的均值和标准差,并在右上角用subplot展示三个通道的均值柱状图,右下角用subplot展示三个通道的标准差柱状图。
最后,用plt.show()将所有的子图展示出来。