Archive
Python: Data Visualization Part-1
Learning : python, pygal, Data Visualization, Bar Chart
Subject: Data visualization using pygal library
pygal is a Data Visualization library in python to help us showing our Data as a graph. In coming several posts we will discover and learn how to use the pygal library in simple and easy configuration and style.
First we need to install pygal packeg, to do so write this:
pip install pygal
Now we need some Data to show, in this leson I am using aGalaxy Tab S4, so all the codes will be tested and applyed on trinket.io website [trinket.io alow us to use pygal package online so we don’t need to install it on our divice]
Type of Chart:
pygal has several types of charts that we can use, here we will list them all then in coming posts will use each one with simple data. So what we have:
Line, Bar, Histogram, XY, Pie, Radar, Box, Dot, Funnel, SolidGauge, Gauge, Pyramid, Treemap, Maps
Some of those charts has a sub-types such as in Bar char we have: Basic, Stacked and Horizontal. Also for each chart we can add a title and labels and we can use some styles.
So let’s start ..
First we will go for the Bar chart, and we have three sub-types as Basic, Stacked and Horizontal.
First chart: Bar chart:
In this part we will demonstrate the Bar Chart, it has three sub-types as Basic, Stacked and Horizontal.
We assume that our data is the Males and Female ages on first marage, the data will be as dictionary (later we will see how to customize each bar)
# Basic Bar Chart using pygal
import pygal
bar_chart = pygal.Bar() # To create a bar graph object
bar_chart.add('Females', [22,25,18,35,33,18])
bar_chart.add('Males', [30,20,23,31,39,44])
bar_chart.title = "Males and Females First Marage Age"
bar_chart.x_labels=(range(1,6))
bar_chart.render()
Sample code for Basic bar chart![]() |
Another sub-type in Bar chart is Horizontal-Bar, it is semelar to the Basic but as if fliped 90 degree. Here is the code ..
# Horizontal Bar Chart using pygal
import pygal
# HorizontalBar()
HBar = pygal.HorizontalBar()
HBar.add('Females', [22,25,18,35,33,18])
HBar.add('Males', [30,20,23,31,39,44])
HBar.title = "Males and Females First Marage Age"
HBar.x_labels=(range(1,6))
HBar.render()
Sample code for Horizontal Bar chart![]() |
Last sub-type in Bar chart is Stacked Bar were all data of each element will be in one bar. Here is the code and example..
# Stacked Bar Chart using pygal
import pygal
# StackedBar()
stackedbar = pygal.StackedBar()
stackedbar.add('Females', [22,25,18,35,33,18])
stackedbar.add('Males', [30,20,23,31,39,44])
stackedbar.x_labels=(range(1,0))
stackedbar.title = "Males and Females First Marage Age"
stackedbar.render()
If we say we have another data-set as “age in First-Divorces” and we want to add this set to the Stacked Bar chart, then we first will create the data-set as:
stackedbar.add(‘Divorses’, [35,22,45,33,40,38])
and we will arrange the code line to be at top,middle or bottom of the bar. Here is the code..
Sample code for stacke Bar chart with Divorce data
|
Next we will talk about Line chart.
:: Data Visualization using pygal ::
| Part-1Bar-Chart | Part-2 | Part-3 | Part-4 |
By: Ali Radwani
Search in site..
Taking pictures is not my main daily practices, but when i start playing with my camera, i really enjoy my self.
Thanks for visiting my Space..
The Archives
- January 2026 (1)
- December 2025 (1)
- August 2025 (13)
- July 2025 (33)
- June 2025 (29)
- May 2025 (32)
- April 2025 (31)
- March 2025 (33)
- February 2025 (30)
- January 2025 (32)
- December 2024 (34)
- November 2024 (32)
- October 2024 (33)
- September 2024 (31)
- August 2024 (31)
- July 2024 (31)
- June 2024 (33)
- May 2024 (31)
- April 2024 (31)
- March 2024 (31)
- February 2024 (29)
- January 2024 (31)
- December 2023 (25)
- November 2023 (3)
- July 2023 (15)
- June 2023 (14)
- May 2023 (3)
- April 2023 (2)
- March 2023 (4)
- February 2023 (1)
- October 2022 (3)
- September 2022 (7)
- August 2022 (9)
- July 2022 (11)
- June 2022 (8)
- March 2022 (7)
- February 2022 (6)
- January 2022 (1)
- December 2021 (1)
- November 2021 (9)
- October 2021 (10)
- September 2021 (10)
- August 2021 (13)
- July 2021 (13)
- June 2021 (12)
- May 2021 (5)
- April 2021 (11)
- March 2021 (12)
- February 2021 (5)
- January 2021 (4)
- December 2020 (1)
- November 2020 (6)
- October 2020 (2)
- September 2020 (2)
- August 2020 (6)
- July 2020 (10)
- June 2020 (6)
- May 2020 (2)
- April 2020 (2)
- March 2020 (9)
- February 2020 (6)
- January 2020 (4)
- December 2019 (9)
- November 2019 (8)
- October 2019 (5)
- August 2019 (12)
- July 2019 (18)
- June 2019 (11)
- April 2019 (16)
- December 2018 (7)
- November 2018 (7)
- April 2018 (2)
- March 2018 (14)
- February 2018 (14)
- January 2018 (16)
- December 2017 (9)
- January 2017 (1)
- November 2016 (6)
- October 2016 (14)
- September 2016 (16)
- August 2016 (14)
- July 2016 (16)
- June 2016 (15)
- May 2016 (2)
- March 2016 (5)
- February 2016 (5)
- January 2016 (17)
- December 2015 (4)
- September 2015 (12)
- August 2015 (13)
- July 2015 (3)
- June 2015 (12)
- May 2015 (9)
- April 2015 (11)
- March 2015 (14)
- February 2015 (15)
- January 2015 (16)
- December 2014 (16)
- November 2014 (15)
- October 2014 (7)
- September 2014 (11)
- August 2014 (11)
- July 2014 (12)
- June 2014 (15)
- May 2014 (14)
- April 2014 (14)
- March 2014 (14)
- February 2014 (12)
- January 2014 (14)
- December 2013 (11)
- November 2013 (13)
- October 2013 (11)
- September 2013 (14)
- August 2013 (10)
- July 2013 (15)
- June 2013 (13)
- May 2013 (23)
- April 2013 (19)
- March 2013 (13)
- February 2013 (11)
- January 2013 (17)
- December 2012 (14)
- November 2012 (12)
- October 2012 (11)
- September 2012 (14)
- August 2012 (14)
- July 2012 (12)
- June 2012 (10)
- May 2012 (16)
- April 2012 (20)
- March 2012 (23)
- February 2012 (13)
- January 2012 (1)
- December 2011 (1)
- October 2011 (2)
- September 2011 (5)
- August 2011 (7)
- July 2011 (13)
- June 2011 (4)
- March 2011 (7)
- February 2011 (13)
- January 2011 (6)
- December 2010 (8)
- November 2010 (10)
- May 2010 (1)
- March 2010 (2)
- December 2009 (1)
- November 2009 (1)
- October 2009 (1)
- August 2009 (1)
- July 2009 (1)
- March 2009 (5)
- February 2009 (3)
- September 2008 (1)
- July 2008 (2)
Calendar…
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | ||||
| 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| 11 | 12 | 13 | 14 | 15 | 16 | 17 |
| 18 | 19 | 20 | 21 | 22 | 23 | 24 |
| 25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
ahradwani ahradwani.com Ali Ali Hassan Radwani animal Art Before and After BNW Camera Code Computer D90 D7100 Design doha Doha-Qatar DohaPort Draw Experiment Flower Flowers fujifilm Fujifilm X-T30ii fujinon 18-55mm Galaxy Home Made HowTo Language Learning Lens Lesson Light light box London London 2012 London 2013 London 2014 London 2023 London 2024 Macro Macro on Flowers moleskin Msheireb museum my sketchbook Nikon Nikon 18-300mm Nikon 35mm Nikon 105mm pen Pencil Photo Photography photos Photos from Qatar photoshop Photoshop action Project Python Qatar radwani RX100M7 S9900 sample image Sketch Sketchbook Sketches Sony RX100vii Stamp street photography Strobist Studio X-T30ii الدوحه - قطر تصويرMost Readed..
Recent Posts..
My Flickr: Hawee - Ta3kees
Visitors Stats
- 137,256 hits



Follow me on Twitter..

