【问题标题】:How to inherit matplotlib in python?如何在python中继承matplotlib?
【发布时间】:2014-08-01 14:32:05
【问题描述】:

当我运行下面的程序时:

import matplotlib
class abc(matplotlib):
    def anything(self):
        print("anything")

aa=abc()

我收到以下错误:

文件“test.py”,第 2 行,在 类 abc(matplotlib):TypeError:调用元类库时出错 module.init() 最多接受 2 个参数(给定 3 个)

我该如何解决?

【问题讨论】:

  • 为什么要尝试从模块继承?你想做什么?错误的原因是 matplotlib 是一个模块实例,而不是一个类。

标签: python inheritance matplotlib


【解决方案1】:

matplotlib 是一个模块/包。你不能继承它,因为它不是一个类。

我能想到的最接近你可以做的事情类似于:

# my_matplotlib.py
from matplotlib import *
import matplotlib

def plot(*args, **kwargs):
    """Overrides matplotlib.plot"""
    print "Hey Dude.  I'm plotting now!"
    return matplotlib.plot(*args, **kwargs)

请注意,我真的不建议这样做...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-10
    • 1970-01-01
    • 2018-03-10
    • 1970-01-01
    • 1970-01-01
    • 2019-01-04
    • 2011-03-15
    相关资源
    最近更新 更多