Improving Visualization Aesthetics using Python

Introduction

In this article we will be discussing how to improve the aesthetics of graphs using python and the best practices that should be kept in mind while creating graphs in order to generate the best possible visualization.

The dataset that has been used to illustrate the examples in this article is publicly available and can be downloaded from this link

To illustrate the key concepts we will use a basic time series plot as an example and we will convert that into a professional & aesthetic graph in 8 simple steps:

Basic to Professional Plot

Basic to Professional Plot

Step 1: Loading the data

First let us have a look at the data so that we can finalize which visualization to create and further improve.

Head Output

Head Output

The above data has an “Order date” column and an “Order ID” column. We will use these two columns to create out visualization.

Step 2: Getting the data in shape to create the graph

First we will group the data by “Order date” and count total Orders at every date. Then let us now aggregate the data at Year-Month level and count total orders at every month. This has been illustrated in the code below:

Dataframe to plot

Dataframe to plot

Step 3: Creating a basic plot

Let’s plot the most basic graph using default code and see what the visualization looks like.

Basic Plot

Basic Plot

The above visualization needs a lot of work and the first thing that can be improved in it is the x-axis labels.

Step 4: Increasing chart size and Improving x-axis labels

In the below code it has been illustrated how improve the following things:

  • reduce x-axis label frequency
  • increase chart size
  • rotate x-axis label
Step 4 output

Step 4 output

Step 5: Adding axis and graph titles

The auto-generated axis-titles may be non-intuitive and confusing so we must always change them and make sure that all the axis titles and graph title is clearly mentioned and easy to understand, so we will make the following improvements to the titles:

  • addition of an intuitive graph title
  • increased the size of titles to make the, more readable
  • changed the title values into more understandable text
Step 5 output

Step 5 output

Step 6: Improving line aesthetics

Improving line or bar aesthetics impacts the overall look of the visualization by a huge margin because the lines and bars are the center of attraction of all plots so we must ensure they are eye-catching in-order to draw the viewers attention.

So we will do the following changes to the line aesthetics to ensure it is highlighted in the whole graph:

  • Addition of markers to the line to highlight the bends of the line
  • Changing the line color to red and increasing the line width
Step 6 output

Step 6 output

Step 7: Adding data labels

It is always a good idea to add data-labels to the graph so that the viewer gets a clear idea about every data point and is able to rightly identify highs and lows in the graph.

Step 8: Adding a theme to the plot

Finally let’s add a theme to the graph to give it a professional look. The attribute “style” can be changes to values “darkgrid”, “white, “dark” and  “ticks” to change the graph theme. All these themes have been illustrated here.

Professional aesthetic plot

Professional aesthetic plot

We have now converted a default basic plot into a professional plot, we can use these concepts to create other professional plots as well.

Complete Code with Github Link

Github Link

You may also like...