What is Plotly graph_object? (How is it different from Express?)

Plotly

 When drawing graphs in Plotly, if you read the documentation or read about it in various articles, you may wonder what the difference is between the two ways of importing and using it. Is there a difference?

Concretely, it looks like this.

# If you are importing matplotlib
import matplotlib.pyplot as plt

# For plotly, there are two types
import plotly.express as px
import plotly.graph_objects as go

 So, in this article, we will summarize one of plotly's graph drawing methods, "graph_objects"!

The difference between Express and graph_objects

 The first question that comes to mind is, "What's the difference?  I'll tell you the conclusion first. "The contents are the same".

 What this means is that when you use a function in Plotly Express, it internally calls graph_objects and returns a value. In other words, some of the Express functions are useful in that they implement things that would take 5-100 lines to draw using graph_objects!

Why am I writing an article about graph_object?

 In this blog, I basically adopt graph_objects when explaining plotly.  The reason for this is that I feel that understanding graph_objects, which is a more fundamental idea, will help you understand Express when you try to use it.

(As of July 1, 2021, most of the articles I've written focus on basic operations, so if you want to use plotly more easily or write less code, please contact me. If you want to use plotly more easily or with less code, I'd be happy to write about Express as well).

What you can do with graph_objects but not with express

1. Cannot use subplot

Plotly Display multiple graphs side by side (make_subplots, set_subplots)
  In this article, I will explain how to use subplots in matplotlib.  In matplotlib, the function can be represented by...

2. Cannot set the second axis

 This is actually the same as 1. because it uses make_subplot, but the difference is that you can put two axis settings in the same graph or not, as shown in the figure below.
Plotly Multiple Axes by make_subplots
 There are times when you want to use multiple axis labels instead of just one. Here is a summary of how to use it, wit...
Copied title and URL