[英]How to prevent scientific notation in the axis offset in matplotlib?
我有一个 plot ,其中 y 轴偏移为5.223e1
。 我宁愿让它说52.23
。 这可以做到吗?
与这个问题不同: 防止 matplotlib.pyplot 中的科学记数法,我有兴趣从偏移量本身中删除科学记数法,而不是整个轴 label。 我想保留偏移量,只是不要用科学计数法。
我认为这只能通过子类化和定义自己的格式 function来完成。
最小的例子:
import matplotlib.pyplot as plt
from matplotlib.ticker import ScalarFormatter
class my_ScalarFormatter(ScalarFormatter):
def format_data(self, value):
return f'{value:.2f}'
fig,(ax1,ax2) = plt.subplots(ncols=2)
ax2.yaxis.set_major_formatter(my_ScalarFormatter())
ax1.set_ylim(52.23, 52.231)
ax2.set_ylim(52.23, 52.231)
ax1.set_title('Default Formatter')
ax2.set_title('Custom Formatter')
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.