简体   繁体   English

如何子类化Pygal图

[英]How to subclass Pygal graphs

I'm looking at subclassing the XY graph in Pygal, as I want to try override some of the Graph's methods such as _x_axis and _y_axis . 我正在尝试在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)

When I try to run this code I get this error: 当我尝试运行此代码时,出现以下错误:

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'

Replacing CustomXY(pygal.XY) with CustomXY(pygal.graph.xy.XY) gives me this error: 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'

What is the preferred way to subclass Pygal graphs? 继承Pygal图的首选方法是什么?

It is an open source project, is there a particular reason you don't want to make the changes in your own fork version of XY? 这是一个开源项目,您是否有特定的原因不想在自己的XY分支版本中进行更改?

http://pygal.org/ http://pygal.org/

We all see the see that banner in the top right... right? 我们都在右上方看到该横幅...对吗?

In all seriousness I am a little thrown off by the class Ghost throwing this error in its init considering that Ghost isn't in the object Hierarchy for your new class. 认真地说,考虑到Ghost不在新类的对象层次结构中,我对Ghost类抛出了一些错误,但在初始化 时却抛出了此错误。

pygal looks like a cool package and I'm interested in what others people have to say here. pygal看起来很酷,我对其他人在这里所说的内容很感兴趣。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM