Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Matplotlib for Python Developers. - Second Edition

You're reading from  Matplotlib for Python Developers. - Second Edition

Product type Book
Published in Apr 2018
Publisher Packt
ISBN-13 9781788625173
Pages 300 pages
Edition 2nd Edition
Languages
Authors (3):
Aldrin Yim Aldrin Yim
Profile icon Aldrin Yim
Claire Chung Claire Chung
Profile icon Claire Chung
Allen Yu Allen Yu
Profile icon Allen Yu
View More author details

Table of Contents (16) Chapters

Title Page
Dedication
Packt Upsell
Contributors
Preface
Introduction to Matplotlib Getting Started with Matplotlib Decorating Graphs with Plot Styles and Types Advanced Matplotlib Embedding Matplotlib in GTK+3 Embedding Matplotlib in Qt 5 Embedding Matplotlib in wxWidgets Using wxPython Integrating Matplotlib with Web Applications Matplotlib in the Real World Integrating Data Visualization into the Workflow Index

Chapter 8. Integrating Matplotlib with Web Applications

Web-based applications (web apps) offer multi-level advantages. First, users can enjoy a unified experience across platforms. Second, since an installation process is not required, users can enjoy a simpler workflow. Lastly, from the perspective of developers, the development cycle can be simplified as less platform-specific code has to be maintained. Given these advantages, more and more applications are being developed online.

Owing to the popularity and flexibility of Python, it makes sense for web developers to use Python-based web frameworks such as Django and Flask to develop web applications. In fact, Django and Flask ranked 6th and 13th out of 175 respectively in terms of popularity, according to http://hotframeworks.com/. These frameworks are batteries included. From user authentication, user administration, and content management to API design, these frameworks have got them all covered. The code base is closely reviewed by...

Installing Docker


Docker allows developers to run applications in self-contained and lightweight containers. Since its introduction in 2013, Docker has quickly gained popularity among developers. At the center of its technology, Docker uses the resource isolation methods of the Linux kernel instead of a full-blown virtualization hypervisor to run applications.

This enables easier development, packaging, deployment, and management of code. Therefore, all code development work in this chapter will be conducted using a Docker-based environment.

Docker for Windows users

There are two ways to install Docker on Windows: the aptly named Docker for Windows package, and Docker Toolbox. I recommend stable versions of the Docker Toolbox because Docker for Windows requires Hyper-V support in 64-bit Windows 10 Pro. Meanwhile, Docker for Windows is not supported by older versions of Windows. Detailed installation instructions can be found at https://docs.docker.com/toolbox/toolbox_install_windows/, but we...

More about Django


Django is a popular web framework that is designed to simplify the development and deployment of web applications. It includes loads of boilerplate code for everyday tasks, such as database model management, frontend templating, session authentication, and security. Django was built around the Model-Template-View (MTV) design pattern.

The model is perhaps the most critical component of MTV. It refers to how you represent your data in terms of different tables and attributes. It also abstracts away the nitty-gritty details of different database engines such that the same model can be applied to SQLite, MySQL, and PostgreSQL. Meanwhile, the model layer of Django would expose engine-specific parameters, such as ArrayField and JSONField in PostgreSQL, for fine-tuning of your data representation.

The template is similar to the role of a view in the canonical MTV framework. It handles the presentation of data to the users. In other words, it doesn't handle the logic of how the...

Showing Bitcoin prices using Django and Matplotlib


We have now established a fully fledged website backbone using just a few commands. I hope you will appreciate the simplicity of using Django for web development. Now, I will demonstrate how we can integrate Matplotlib charts into a Django site, which is the key topic of this chapter.

Creating a Django app

An app in the Django ecosystem refers to an application that handles a specific function within a site. For instance, our default project comes with the profile and account apps already. With the terminology clarified, we are set to build an app to display the latest price of bitcoin.

We should keep our development server running in the background. When the server detects any changes to our code base, it will reload automatically to reflect the changes. Therefore, right now, we need to launch a new Terminal and attach to the running server container:

docker exec -it 377bfb2f3db4 bash

The strange-looking numbers before bash refer to the ID of...

Summary


In this chapter, you learned about a popular framework made to simplify the development and deployment of web applications, called Django. You further learned about integrating Matplotlib charts into a Django site.

In the next chapter, we will cover some useful techniques to customize figure aesthetics for effective storytelling.

lock icon The rest of the chapter is locked
You have been reading a chapter from
Matplotlib for Python Developers. - Second Edition
Published in: Apr 2018 Publisher: Packt ISBN-13: 9781788625173
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}