Python Science Plotting

Creating Various Plot Types and Subplots with Plotly

Use plotly to create bar charts, histograms, scatter plots, bubble chart, and box plots and arrange these with subplots

Naveen Venkatesan
Towards Data Science
8 min readMay 4, 2022
Photo by Luke Chesser on Unsplash

Now that you have some background in using the plotly package (if you want a good introduction, you can read a previous article that I wrote), you may want to expand some of the plotting options that you have. In this post, I will demonstrate some of the other basic plot options within plotly and how to set up paneled figures by utilizing subplots. We will look at bar charts, histograms, scatter/bubble charts, and box plots. As we did in the my previous article on this topic, we will use plotly.graph_objects to build our figures from scratch.

Bar Charts

Let’s start by creating some dummy data to plot in our bar chart. We can do so using numpy as follows:

# import packages
import numpy as np
# create dummy data
vals = np.ceil(100 * np.random.rand(5)).astype(int)
keys = ["A", "B", "C", "D", "E"]

Now we can plot each of these key-value pairs on a bar plot. The first thing we need to do is create a figure using plotly.graph_objects:

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Towards Data Science
Towards Data Science

Published in Towards Data Science

Your home for data science and AI. The world’s leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.

Naveen Venkatesan
Naveen Venkatesan

Written by Naveen Venkatesan

Data Scientist • Materials Scientist • Musician • Golfer

No responses yet

What are your thoughts?