Book Image

Learning Python Data Visualization

By : Chad R. Adams
Book Image

Learning Python Data Visualization

By: Chad R. Adams

Overview of this book

<p>The best applications use data and present it in a meaningful, easy-to-understand way. Packed with sample code and tutorials, this book will walk you through installing common charts, graphics, and utility libraries for the Python programming language.</p> <p>Firstly you will discover how to install and reference libraries in Visual Studio or Eclipse. We will then go on to build simple graphics and charts that allow you to generate HTML5-ready SVG charts and graphs, along with testing and validating your data sources. We will also cover parsing data from the Web and offline sources, and building a Python charting application using dynamic data. Lastly, we will review other popular tools and frameworks used to create charts and import/export chart data. By the end of this book, you will be able to represent complex sets of data using Python.</p>
Table of Contents (16 chapters)
Learning Python Data Visualization
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Gauge charts


Gauge charts display data in a graph style that is similar to speedometers in automobiles. They also work well with multiple datasets but not one with a single dataset. In the following code, we have an example of a gauge chart, which is a very simple pygal chart. This time, we will use some new data; in this case, we will use a dataset that represents the space shuttle speed from the time of launch to 20 minutes.

Let's look at our sample code and our chart in the following code snippet. Copy the code into your editor of choice, and ensure that you save the file to gauge_chart.svg:

# -*- coding: utf-8 -*-
import pygal

gauge_chart = pygal.Gauge()
gauge_chart.title = 'Speed of space shuttle during takeoff'
gauge_chart.x_labels = ['Pre-takeoff', '5 min', ' 10 min', '15 min', '20 min']
gauge_chart.add('Pre-takeoff', 0)
gauge_chart.add('5 min', 96)
gauge_chart.add('10 min', 167)
gauge_chart.add('15 min', 249)
gauge_chart.add('20 min', 339)

gauge_chart.render_to_file('gauge_chart...