以下代码用于设置横坐标轴刻度格式现在我要为format_sec函数增加一个参数tick默认为1000请帮我修改一下sec_formatter = tickerFuncFormatterformat_secdef format_secx tick=1000 if tick==1000#1000ns=1ms t=1fformatx1000# elif tick==10
以下是修改后的代码:
def format_sec(x, tick=1000):
if tick==1000:#1000ns=1ms
t='{:.1f}'.format(x/1000)#
elif tick==100:#100ns
t='{:.1f}'.format(x/10000)
return t
tick = 1000 # 默认刻度为1000 sec_formatter = ticker.FuncFormatter(lambda x, pos: format_sec(x, tick)) # 增加一个lambda函数,将tick作为参数传递给format_sec函数 plt.gca().xaxis.set_major_formatter(sec_formatter)
原文地址: https://www.cveoy.top/t/topic/cvEp 著作权归作者所有。请勿转载和采集!