17Plotting

Plotting is a key component when looking to work with data, and Python has a number of plotting libraries. In this chapter, we cover plotting in great detail starting with creating basic plots directly from Pandas DataFrames to getting more control using matplotlib all the way through to using Seaborn. The chapter is fully example driven with code snippets alongside the graphics they produce. The aim of including both is to give you the ability to see what the code produces but also act as a reference for when you want to produce graphs. The examples are based on datasets that come from with Python with many being taken from the documentation with the idea of giving them greater explanation to help you understand what is happening. The packages that we will look to use in this chapter are imported below.

image

17.1 Pandas

Initially, we will look at plotting methods on Series and DataFrame objects in pandas. One of the great things about pandas is that we have inbuilt plotting methods that we can call and produce plots from. This allows very fast visual presentation of datasets that we want to analyse.

image
image

Figure 17.1 Line plot of sepal length.

The previous code snippets ...

Get The Python Book now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.