Skip to content
Related Articles

Related Articles

Improve Article
Styling Graphs in Pygal
  • Last Updated : 10 Jul, 2020

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






# 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

Output:

Example 2: Styling Stacked Line Chart

Python3




# 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

Output:

Example 3: Styling Bar Chart

Python3




# 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

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. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :