我试着在X轴上画四个数字标签,小数点后两位,例如“1475.88”。如您所见,Matplotlib将标签缩短为科学格式1.478e3
如何以定义的间距显示完整地物
下面的代码:
with plt.style.context('seaborn-whitegrid'):
# Plot the SVP data
plt.figure(figsize=(8, 8))
plt.plot(speed_x_clean, depth_y_clean)
plt.plot(smoothed_speed, smoothed_depth)
plt.scatter(float(speed_extrapolated), float(depth_extrapolated),marker='X', color='#ff007f')
# Add a legend, labels and titla
plt.gca().invert_yaxis()
plt.legend(('Raw SVP', 'Smoothed SVP'), loc='best')
plt.title('SVP - ROV '+ '['+ time_now + ']')
plt.xlabel('Sound Velocity [m/s]')
plt.ylabel('Depth [m]')
# plt.grid(color='grey', linestyle='--', linewidth=0.25, grid_animated=True)
ax = plt.axes()
plt.gca().xaxis.set_major_locator(plt.AutoLocator())
plt.xticks(rotation=0)
plt.show()
带两位小数的标签
使用ticker FuncFormatter可以实现任何用户定义的格式
以定义的间距设置标签
使用set_xticks和set_yticks,可以按定义的间距设置标签数量
独立示例
一个完全独立的示例可能如下所示(简单正弦波):
输出
下面是示例程序的输出:它有四个图形标签,x轴上有两个小数位:
相关问题 更多 >
编程相关推荐