3

In Pygal, is there a way to change the stroke width (make it thicker for example)?

I didn't find anything related to that in the docs.

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Tzach
  • 12,889
  • 11
  • 68
  • 115

2 Answers2

0

There is a to_dict method on the Style class that is very helpful for creating custom styles.

>>> CleanStyle.to_dict()
{'opacity': '.8', 'foreground': 'rgba(0, 0, 0, 0.9)', 'plot_background': 'rgba(240, 240, 240, 0.7)', 'stroke_style': 'round', 'foreground_light': 'rgba(0, 0, 0, 0.9)', 'transition': '250ms', 'foreground_dark': 'rgba(0, 0, 0, 0.5)', 'stroke_dasharray': '0,0', 'opacity_hover': '.9', 'stroke_width': 1.0, 'colors': ('rgb(12,55,149)', 'rgb(117,38,65)', 'rgb(228,127,0)', 'rgb(159,170,0)', 'rgb(149,12,12)'), 'background': 'transparent', 'font_family': 'monospace'}

Here's how you might create a custom style with a thick stroke width.

>>> from pygal.style import Style, CleanStyle
>>> style_arg = CleanStyle.to_dict()
>>> style_arg['stroke_width']=10
>>> HeavyCleanStyle = Style(**style_arg)
>>> HeavyCleanStyle.to_dict()
{'opacity': '.8', 'foreground': 'rgba(0, 0, 0, 0.9)', 'plot_background': 'rgba(240, 240, 240, 0.7)', 'stroke_style': 'round', 'foreground_light': 'rgba(0, 0, 0, 0.9)', 'transition': '250ms', 'foreground_dark': 'rgba(0, 0, 0, 0.5)', 'stroke_dasharray': '0,0', 'opacity_hover': '.9', 'stroke_width': 10.0, 'colors': ('rgb(12,55,149)', 'rgb(117,38,65)', 'rgb(228,127,0)', 'rgb(159,170,0)', 'rgb(149,12,12)'), 'background': 'transparent', 'font_family': 'monospace'}
ChrisGuest
  • 3,398
  • 4
  • 32
  • 53
0

Try the following on stroke_style

chart.add("Title", [], stroke_style={'width': 5})
Emmanuel Mtali
  • 4,383
  • 3
  • 27
  • 53
falselight
  • 527
  • 7
  • 11