Why are subplots made complicated?

I started using plotly instead of matplotlib and seaborn recently. So far my experience has been very positive. However, one annoying thing is the way subplots are created. For example I need to do:

from plotly.subplots import make_subplots
import plotly.graph_objects as go

fig = make_subplots(rows=1, cols=2)

    go.Scatter(x=[1, 2, 3], y=[4, 5, 6]),
    row=1, col=1

    go.Scatter(x=[20, 30, 40], y=[50, 60, 70]),
    row=1, col=2

fig.update_layout(height=600, width=800, title_text="Side By Side Subplots")

While there is nothing wrong with this, I think it’s rather annoying that now I have to use these go plot instead of regular plots.

What is the reason behind this? Why would it simply not keep the original syntax? It can be quite frustrating. For example, if my single plot code looks like:

px.scatter(range(10), range(10))

And if I wanted to put this on a subplot I need to:

  • use go object and remember to use capital S: go.Scatter
  • now give arrays either as a dict or named args x and y
  • change my code from a range to a list, numpy, array or pandas etc.

Now multiply this by a number of different plotting options: line, scatter, histogram etc and you get to either memorize a huge number of functions that do the same thing or you will keep getting errors and wasting time on googling the right one.

Additionally, in matplotlib it is quite useful to be able to create an axis – ax and then pass it when creating plots which then puts all the plots on that axis. This works quite well with pandas plots where you can easily put two plots from different dataframes on the same axis. Is anything similar possible here?

1 Like