Python Friday #191: Often used Diagrams for Plotly

After our first steps with the interactive plots of Plotly, we will now explore the different diagrams we can use to visualize our data.

This post is part of my journey to learn Python. You find the code for this post in my PythonFriday repository on GitHub.

 

Line plot / Line chart

We can create a line plot with the line() method of Plotly Express:

This creates us a basic line plot:

Our data visualised as a line plot.

 

Bar chart

For the categorical values, we can create a bar chart with the bar() method:

This gives us a vertical bar for each of the values:

Our data plotted as a bar chart.

 

Scatter plot

The scatter() method allows us to create a plot with dots for our values:

This turns the built-in data set iris into a scatter plot:

The scatter plot automatically adjusts the axes to fit the data.

 

Histogram

We can create a histogram with the histogram() method:

This shows us the distribution of the values:

We get a histogram for the total_bill column of the tips data set.

 

Box plot

With the box() method we can get our statistical box plots:

By specifying the value of day for the colour, we get the separation of time and day in one go for our box plot:

We get a box plot for each time and each day.

 

Pie chart

To create a pie chart, we can use the pie() method:

This creates a pie chart, but the values on the pie are not always easy to read:

The pie chart works out of the box, but the contrast between the values and the segments is not always high enough.

 

Next

These basic plots allow us to visualize our data in most cases. However, sometimes that is not enough. Plotly comes with its own specific diagrams that we explore next week.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.