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

XY charts


XY charts are typically used in scientific data to show multiple values at various points. They can display negative values as well. They also overlay multiple sets of values for easy readability. Let's build a simple XY chart with two points. Copy the following code into your Python file and run the application, and save your SVG file output as xy_chart.svg:

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

xy_chart = pygal.XY()
xy_chart.add('Value 1', [(-50, -30), (100, 45)])

xy_chart.render_to_file("xy_chart.svg")

Open the xy_chart.svg file; the result is shown in the following screenshot:

Note how pygal highlights the 0 lines on both the x and y coordinates; again, this is free styling provided by the pygal library to indicate negative values. Also, take note of the add() function, of how each value is noted as an (x, y) coordinate, grouped together in an array. Let's build another chart, this time with two plots; in this case, we build with Value 1 and Value 2. Copy the following code and...