Matplotlib vs. Plotly: Let’s Decide Once and for All



Original Source Here

Matplotlib vs. Plotly: Let’s Decide Once and for All

Deep and rapid comparison in terms of 7 key aspects

Goofy Image by Author

There is an annoying habit of soccer fans. Whenever a young but admittedly exceptional player emerges, they compare him to legends like Messi or Ronaldo.

They choose to forget that the legends have been dominating the game since before the newbies had regrown teeth.

Comparing Plotly to Matplotlib was, in a sense, similar to that in the beginning. Matplotlib had been in heavy use since 2003, and Plotly had just come out in 2014.

Many were bored with Matplotlib by this time, so Plotly was warmly welcomed for its freshness and interactivity. Still, the library couldn’t hope to steal the top spot as the king of Python plotting packages from Matplotlib.

In 2019, things changed dramatically when Plotly released its Express API in July. This fueled an explosion of interest in the library, and people started using it left and right.

With another major version (5.0.0) released in June this year, I think Plotly matured more than enough to compare it to Matplotlib seriously.

With that said, let’s get started:

Custom function to plot the scores. The full function body can be seen on this GitHub gist I created.

1. API usability

Let’s start by comparing the ease of use of their APIs. Both offer high-level and low-level interfaces to interact with the core functionality.

1.1 Consistency of higher-level APIs (Pyplot vs. Express)

On the one hand, Express excels in consistency. It only contains higher-level functions to access the built-in plots. It does not introduce new ways of performing existing functionality — it is a wrapper. All plot calls to Express return the core Figure object.

On the other hand, Pyplot packages all plotting functions and customizations into a single, new API. Even though plot calls have the same signature, customization functions differ from those in the OOP API.

This means you have to spend your time learning the differences if you want to switch interfaces.

Besides, creating plots returns different objects under the hood. For example, plt.scatter returns a PathCollection object whereas plt.boxplot returns a dictionary. This is because Matplotlib implements different base classes for each plot type. It can be truly confusing for many.

plot_scores(mpl=0, px=1)

AI/ML

Trending AI/ML Article Identified & Digested via Granola by Ramsey Elbasheer; a Machine-Driven RSS Bot

%d bloggers like this: