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

Preface

Greetings, this is Chad Adams, and welcome to Learning Python Data Visualization. In this book, we will cover the basics of generating dynamic charts and general graphics with code using the Python programming language. We will use the pygal library, a simple yet powerful graphing library written for Python, to explore the different types of charts we can create for various kinds of data.

We will also review the Python language itself and discuss working with file I/O and cover topics on working with data. We will then parse that data into a chart to create a dynamic charting application. We will also touch on more popular (and more advanced) libraries such as matplotlib and Plotly and build charts using these libraries and explore their features.

With this book, we will explore and build data visualizations using the basic toolsets used in many popular charting applications for the scientific, financial, medical, and pharmaceutical industries.

What this book covers

Chapter 1, Setting Up Your Development Environment, will discuss the installation process for Python on Windows, Mac, and Ubuntu. We will review the easy_install and pip package managers for Python and discuss common issues when installing third-party libraries for Python.

Chapter 2, Python Refresher, will quickly review the Python language and common libraries found in most Python developers' tool belts. We will also ease into building charts by creating custom graphics with nothing but code and learn about saving files to the filesystem.

Chapter 3, Getting Started with pygal, will cover the basics of the pygal library, a simple charting library that generates charts in HTML5-ready SVG files. We will build some basic charts using the library, some of which include line charts, bar charts, and scatter plots.

Chapter 4, Advanced Charts, will cover more complex charts in the pygal library such as box plots, radar charts, and worldmap charts.

Chapter 5, Tweaking pygal, will discuss the optional settings we can give our pygal charts such as adjusting the font size and the positioning of labels and legends. We will also cover the French country map chart in the pygal library using it as an example.

Chapter 6, Importing Dynamic Data, will go over the finer points of pulling data from the Web using the Python language and its built-in libraries and cover parsing XML, JSON, and JSONP data.

Chapter 7, Putting It All Together, will build a simple chart that takes what we learned from the past chapters and builds a dynamic pygal-based chart using data from the Web.

Chapter 8, Further Resources, will review some very popular charting libraries such as matplotlib and Plotly, go over building sample charts for each library, and cover resources for further reading.

Appendix, References and Resources, will list some popular data visualization libraries for Python as well as some helpful utilities.

What you need for this book

You will need Windows, Mac, or an Ubuntu system that is running Python 2.7 32-bit or Python 2.7 64-bit. You will need to have administrator rights on this system. You will also need a Python text editor such as Eclipse or Visual Studio with Python Tools. For Chapter 8, Further Resources, you will also need Python 3.4 or higher. Python 2.7 and 3.4 can be installed alongside each other.

Who this book is for

If you're new to the Python language and are looking at getting into building charts using Python, this is a great resource to get started. If you have done a bit of Python development already but have not ventured into graphics and charts, there is plenty of information in this book with regards to creating these.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "Create a text file called PyREADME.txt and save it to your project's directory."

A block of code is set as follows:

def main():
    print("Hello, World")
main()

Any command-line input or output is written as follows:

sudo pip install pygal

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Click on OK on both windows to save and reboot your PC again."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.