pygal.Line()可以修改点颜色吗

pygal.Line()绘制折线图要如何修改点的颜色?Style里好像没有点颜色的设置,add里也只有dots_size。果然折线图还是得在matplotlib里用才方便吗😢

单独修改点的好像无法控制,但是点线可以配置颜色。要是生成svg文件,可以自己修改生成的svg文件中的样式。。pygal生成的点线样式都是顺序的,color-0,color-1,color-2依次类推,自己写个样式覆盖掉对应的样式的fill(圆点)和stroke颜色(线条)就行。有帮助麻烦点个采纳【本回答右上角】,谢谢~~

img

import pygal
from pygal.style import Style
custom_style = Style(colors=('red', 'black', 'blue', 'yellow', 'gray'))

chart = pygal.Line(fill=False,style=custom_style)
chart.add('A', [1, 3,  5, 16, 13, 3,  7])
chart.add('B', [5, 2,  3,  2,  5, 7, 17])
chart.add('C', [6, 10, 9,  7,  3, 1,  0])
chart.add('D', [2,  3, 5,  9, 12, 9,  5])
chart.add('E', [7,  4, 2,  1,  2, 10, 0])
chart.render()
chart.render_to_file("x.svg")

其他配置可以参考: http://www.pygal.org/en/stable/documentation/custom_styles.html http://www.pygal.org/en/stable/documentation/custom_styles.html

有兴趣也可以自己扩展 python\Lib\site-packages\pygal\style.py这个文件color属性,fill和stroke单独配置一个颜色

    def get_colors(self, prefix, len_):
        """Get the css color list"""
        def color(tupl):
            """Make a color css"""
            return ((
                '%s.color-{0}, %s.color-{0} a:visited {{\n'
                '  stroke: {1};\n'
                '  fill: {1};\n'
                '}}\n') % (prefix, prefix)).format(*tupl)