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
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
: