Combining Plotly Charts


Intro

I get a lot of questions about building and assembling Plotly charts, and I wanted to include a few Python-only examples below.

Other libraries:

I don’t use Plotly exclusively, but I do use it a lot. I also use bokeh, seaborn, and, less frequently, altair/vega.

Combining Charts with Plotly

Plotly provides two APIs, the simple plotly.express and more comprehensive graph_objects

plotly.express is ultimately the same as graph_objects; it’s just a much simpler interface that does much of what you’ll need.

In most cases, we’ll build chart(s) in plotly.express and then fine-tune or merge them in graph_objects. A few reasons:

  • Aligning the X axis: separate px figures may end up with unaligned X axes, making things look visually weird.
  • Tiling: Sometimes, you might want to show a grid of charts rather than a single chart
  • Overlay two chart elements, such as a line and a bar chart.
  • Using secondary_y axes: a different Y axis for specific series

plotly_combining.ipynb

plotly_combining