我正在考虑在Pygal中对XY图进行子类化,因为我想尝试覆盖图的一些方法,如_x_axis和_y_axis。
import pygal
from pygal.style import Style, CleanStyle
class CustomXY(pygal.XY):
def __init__(self, *args, **kwargs):
super(CustomXY, self).__init__(*args, **kwargs)
def _x_axis(self):
pass
def _y_axis(self):
pass
scatter = CustomXY(stroke=False, show_y_guides=False, truncate_legend=20)当我尝试运行这段代码时,我得到了这个错误:
Traceback (most recent call last):
File "pygal_test2.py", line 12, in <module>
scatter = CustomXY(stroke=False, show_y_guides=False, truncate_legend=20)
File "pygal_test2.py", line 6, in __init__
super(CustomXY, self).__init__(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/pygal/ghost.py", line 71, in __init__
self.cls = REAL_CHARTS[name]
KeyError: 'CustomXY'用CustomXY(pygal.graph.xy.XY)替换CustomXY(pygal.XY)会出现以下错误:
Traceback (most recent call last):
File "pygal_test2.py", line 12, in <module>
scatter = CustomXY(stroke=False, show_y_guides=False, truncate_legend=20)
File "pygal_test2.py", line 6, in __init__
super(CustomXY, self).__init__(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/pygal/graph/line.py", line 33, in __init__
super(Line, self).__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'stroke'什么是Pygal图的子类化的首选方法?
发布于 2015-03-30 14:58:36
这是一个开源项目,有没有什么特别的原因让你不想在自己的XY分支版本中进行修改呢?
http://pygal.org/
我们都看到右上角的see that横幅...对吗?
说真的,我有点被Ghost类弄糊涂了,它在它的初始化中抛出了这个错误,因为它不在你的新类的对象层次结构中。
pygal看起来像一个很酷的软件包,我对其他人在这里有什么要说的很感兴趣。
https://stackoverflow.com/questions/29339279
复制相似问题