我正在研究在 Pygal 中对 XY 图进行子类化,因为我想尝试覆盖一些 Graph 的方法,例如_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.XY)
给 CustomXY(pygal.graph.xy.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 图进行子类化的首选方法是什么?