【问题标题】:How to change stroke color in pygal?如何在pygal中更改笔触颜色?
【发布时间】:2016-03-04 12:22:44
【问题描述】:

如何设置一个为红色,第二个为蓝色?

import pygal

chart = pygal.Line()

chart.x_labels = range(5)
chart.add('one', [1, None, 3, None, 5])
chart.add('two', range(5))

chart.render_to_png(__file__ + '-linear.png')

【问题讨论】:

    标签: python python-2.7 pygal


    【解决方案1】:

    您可以使用 Pygal 的 Custom Styles 为您正在加载的系列定义特定颜色。唯一的缺点是颜色是根据系列顺序分配的,因此在您的情况下,您应该将颜色参数设置为('red','blue'),以便它们与您的系列顺序匹配。

    【讨论】:

      【解决方案2】:

      您可以按如下方式添加自定义样式。

      from pygal.style import Style
      
      yourCustomStyle = Style(
          ...
          colors=['#hex_color1', '#hex_color2', ...],
          ...
      )
      
      yourChart = pygal.Line(style=yourCustomStyle)
      yourChart.add('Series1', [value1, value2, value3, ...])
      yourChart.add('Series2', [value1, value2, value3, ...])
      ...
      yourChart.render()
      

      您有许多样式选项来更改颜色、字体大小、字体系列、背景、透明度等... 查看官方documentation here

      到我发布此内容时,文档中存在错误。他们为示例中的colors 选项提供了颜色元组而不是列表。您必须使用 list[] 在自定义样式中添加颜色。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-12-16
        • 1970-01-01
        • 2015-05-28
        • 1970-01-01
        • 2019-05-09
        • 2019-07-18
        • 1970-01-01
        • 2021-05-16
        相关资源
        最近更新 更多