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) 中添加x轴y轴标签
时间: 2023-12-08 13:05:45 浏览: 156
r_ieee_vals_.rar_John A
可以使用以下代码在函数中添加x轴和y轴标签:
```python
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')
self.ax1.set_xlabel('Time')
self.ax1.set_ylabel('Clients Ratio')
plt.savefig('output.png', dpi=300)
```
在上面的代码中,我们使用set_xlabel()和set_ylabel()函数分别添加x轴和y轴标签。这将在保存为PNG文件之前在图表中显示标签。
阅读全文