Treemap 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.

Treemap in Pygal

Treemap is a chart that is used for displaying echelons data using planted figures mainly rectangles. Each branch of the tree is in rectangular form and then which is macadamize with smaller rectangles to represent sub-branches. The color and the pattern are fixed in such a way in a treemap structure, that it won’t be difficult to understand the material. The second advantage of making treemap is they take less space in layout and can display thousands of items on a screen simultaneously. It can be created using Treemap() method.

Syntax:

treemap = pygal.Treemap()

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing pygal
import pygal
import numpy
  
  
# creating the chart object
treemap = pygal.Treemap()
  
# naming the title
treemap.title = 'Treemap'
  
  
# Random data
treemap.add('A', numpy.random.rand(5))
treemap.add('B', numpy.random.rand(5))
treemap.add('C', numpy.random.rand(5))
treemap.add('D', numpy.random.rand(5))
  
treemap

chevron_right


Output:



Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

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.