当前位置:网站首页>Matplotlib set axis scale interval
Matplotlib set axis scale interval
2022-06-22 20:00:00 【Just one word】
I wanted the horizontal axis to show 1-20 The integer of , Interval between scales 1, But the plot shows floating point numbers
plt.title('train loss')
plt.plot(np.arange(1,len(losses)+1), losses)
plt.plot(np.arange(1,len(eval_losses)+1), eval_losses)

After checking the data , Find two ways :
The first is through MultipleLocator Class to achieve
from matplotlib.pyplot import MultipleLocator # Import this class , Set the axis spacing
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)

The second is to convert the horizontal axis coordinate range into a string
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)

边栏推荐
- 漫话Redis源码之一百一二十
- Peking University - robust task representation for off-line meta reinforcement learning through contrastive learning
- Upgrade VS2008 crystal report to the corresponding version of vs2013
- matplotlib设置坐标轴刻度间隔
- 优化了一半的SQL
- 2. what is mechanical design?
- 一文带你读懂内存泄露
- AttributeError: ‘KeyedVectors‘ object has no attribute ‘wv‘
- 堆排序(原理加代码)
- 1.2-----机械设计工具(CAD软件)和硬件设计工具(EDA软件)及对比
猜你喜欢
随机推荐
AttributeError: ‘KeyedVectors‘ object has no attribute ‘wv‘
Initial experience of ABAQUS using RSG drawing plug-in
使用 Order by 与 rownum SQL 优化案例一则
自定义控件AutoScaleMode为Font造成宽度增加的问题
【深入理解TcaplusDB技术】TcaplusDB 表管理——重建表
误用append案例一则
图的定义及术语
About Random Forest
Quick indent usage in VIM
Some problem records of openpnp using process
MySQL的函数
【深入理解TcaplusDB技术】TcaplusDB机器如何下架
【深入理解TcaplusDB技术】TcaplusDB运维——日常巡检
NAND闪存(NAND Flash)颗粒SLC,MLC,TLC,QLC的对比
0.1----- process of drawing PCB with AD
Concordia University | volume product cycle network for reward generation in reinforcement learning
The custom control autoscalemode causes the problem of increasing the width of font
AB打包有的Shader没有触发IPreprocessShaders的回调
Canvas picture frame
lua--数据类型、变量、循环、函数、运算符的使用









