找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 3574|回复: 0

[求助] 函数传参

1

主题

1

帖子

1

积分

贫民

积分
1
邓志森 发表于 2022-1-24 11:35:30 | 显示全部楼层 |阅读模式
class MyFormatter(Formatter):
    def __init__(self, dates, fmt='%Y-%m-%d'):
        self.dates = dates
        self.fmt = fmt

    def __call__(self, x, pos=0):
        'Return the label for time x at position pos'
        ind = int(np.round(x))
        if ind >= len(self.dates) or ind < 0:
            return ''

        return self.dates[ind].strftime(self.fmt)

formatter = MyFormatter(df['data2'])

ax1.xaxis.set_major_formatter(formatter) 为什么formatter不带参数  就可以执行__call__函数。 __call__里面的x值是怎么传进去的??   
请大神指导一下
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表