当前位置:网站首页>matplotlib设置坐标轴刻度间隔
matplotlib设置坐标轴刻度间隔
2022-06-22 18:28:00 【单单一个越字】
本来是想让横轴显示1-20的整数,刻度之间间隔1,但是画出图来却显示有浮点数
plt.title('train loss')
plt.plot(np.arange(1,len(losses)+1), losses)
plt.plot(np.arange(1,len(eval_losses)+1), eval_losses)

经查资料,找到两种方法:
第一种是通过MultipleLocator类来实现
from matplotlib.pyplot import MultipleLocator #导入此类,设置坐标轴间隔
plt.title('train loss')
x_major_locator=MultipleLocator(1)
ax=plt.gca()
ax.xaxis.set_major_locator(x_major_locator)
plt.plot(np.arange(1,len(losses)+1), losses)
plt.plot(np.arange(1,len(eval_losses)+1), eval_losses)

第二种是将横轴坐标范围转换成字符串
plt.title('train loss')
plt.plot(np.arange(1,len(losses)+1).astype(np.str), losses)
plt.plot(np.arange(1,len(eval_losses)+1), eval_losses)

边栏推荐
- 使用 qrcodejs2 生成二维码详细API和参数
- .Net 5.0 通过IdentityServer4实现单点登录之oidc认证部分源码解析
- How to choose smart home? Take a look at this shopping guide
- 取zip包中的文件名
- 商业智能BI数据仓库中的指标、维度和模型到底是什么?
- 修改隐含参数造成SQL性能下降案例之一
- Ts as const
- 从11小时到25秒--还有优化空间吗?
- How to judge whether text is an array in the slot
- NLP-D57-nlp比赛D26&刷题D13&读论文&&找了一个多小时bug
猜你喜欢
随机推荐
小甲鱼老师《带你学C带你飞》的后续课程补充
1.3-----Simplify 3D切片软件简单设置
Nrf51822 peripheral learning
故障分析 | 从 data_free 异常说起
what? Homekit, Micah, aqara and other ecosystems can also be linked with tmall elf ecology through zhiting?
Solution of off grid pin in Altium Designer
canvas给图片画框框
自定义控件AutoScaleMode为Font造成宽度增加的问题
How to judge whether text is an array in the slot
在线生成占位图片
Adapter mode of structural mode
Take the file name in the zip package
第一篇 热身--隐式类型转换还是其他?
使用 Order by 与 rownum SQL 优化案例一则
0816飞达的缺点(改进方向)
从11小时到25秒--还有优化空间吗?
MySQL数据库DQL查询操作
给对象赋值
Fault analysis | from data_ Free exception
产品几何技术规范(GPS) 线性尺寸公差ISO代号体系









