Open In App

Styling Graphs in Pygal

Improve
Improve
Like Article
Like
Save
Share
Report

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:



Last Updated : 10 Jul, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads