Styling Graphs in Pygal

Pygal is a Python module that is mainly used to build SVG (Scalar Vector Graphics) graphs and charts. SVG is a vector-based graphics in the XML format that can be edited in any editor. Pygal can create graphs with minimal lines of code that can be easy to understand and write.

Pygal is the Python module which provides 14-built in styles under the pygal.style class which are as follows:

  • DarkStyle
  • NeonStyle
  • DarkSolarizedStyle
  • LightSolarizedStyle
  • LightStyle
  • CleanStyle
  • RedBlueStyle
  • DarkColorizedStyle
  • LightColorizedStyle
  • TurquoiseStyle
  • LightGreenStyle
  • DarkGreenStyle
  • DarkGreenBlueStyle
  • BlueStyle

Note: Any graph can be styled using these style by passing the style name in the style argument.

Example 1: Styling Funnel graph

Python3



filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pygal
import pygal
from pygal.style import NeonStyle
  
# creating the chart object
funnel = pygal.Funnel(style = NeonStyle)
  
# naming the title
funnel.title = 'Funnel'        
  
# Random data
funnel.add('A', [26, 22, 39, 39, 32, 30, 33, 24, 24, 30])
funnel.add('B', [31, 40, None, None, None, None, 40, 32, 25, 31])
funnel.add('C', [37, 27, 31, 20, None, 32, 24, 39, 29, 22])
funnel.add('D', [38, None, 20, 29, 33, 23, 32, 33, 32, 23])
  
funnel

chevron_right


Output:

Example 2: Styling Stacked Line Chart

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pygal
import pygal
from pygal.style import LightSolarizedStyle
  
# creating the chart object
line = pygal.StackedLine(fill = True, style = LightSolarizedStyle)
  
# naming the title
line.title = 'Stacked Line'        
  
# Random data
line.add('A', [26, 22, 39, 39, 32, 30, 33, 24, 24, 30])
line.add('B', [31, 40, None, None, None, None, 40, 32, 25, 31])
line.add('C', [37, 27, 31, 20, None, 32, 24, 39, 29, 22])
line.add('D', [38, None, 20, 29, 33, 23, 32, 33, 32, 23])
  
line

chevron_right


Output:

Example 3: Styling Bar Chart

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pygal
import pygal
from pygal.style import BlueStyle
  
# creating the chart object
bar = pygal.Bar(fill = True, style = BlueStyle)
  
# naming the title
bar.title = 'Bar Chart'        
  
# Random data
bar.add('A', [26, 22, 39, 39, 32, 30, 33, 24, 24, 30])
bar.add('B', [31, 40, None, None, None, None, 40, 32, 25, 31])
bar.add('C', [37, 27, 31, 20, None, 32, 24, 39, 29, 22])
bar.add('D', [38, None, 20, 29, 33, 23, 32, 33, 32, 23])
  
bar

chevron_right


Output:


Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up


If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.