Hacker News new | ask | show | jobs
by mlurp 1867 days ago
I have an unpopular opinion: matplotlib sucks, but it's going to be really hard to improve on it.

I don't think I need to give anyone reasons why it sucks, but the reason it's going to be hard to replace is that it can do so much. You can make other plotting libraries that are way easier to do a small subset of things with, but as soon as you want strange, lower level, customizable things, you start having to build in little hacks and workarounds. If you have enough of these, you'll eventually get mpl.

2 comments

Anyone who plans to spend more than an hour using matplotlib should study this page: https://matplotlib.org/stable/tutorials/introductory/lifecyc...

I wanted to draw something I thought would be simple using matplotlib or seaborn. The components were themselves pretty standard:

1. A combo chart (two y variables: one as a line, one as vertical bars).

2. A facet grid (multiple charts with the same axis definition, with each chart representing a slice of the data).

#1 is easy in Excel

#2 is easy in Matplotlib

So I thought the combination of the two would be easy in Matplotlib. At first, it wasn't easy.

It turns out that, if you try and learn matplotlib by googling examples as and when you need them, you may not build a good mental model of how matplotlib charts work. So you hit a wall when you try to do something for which there's no good example online.

But if you read the documentation (particularly the page linked above), things get much easier and the frustration melts away.

Not to disagree... as a regular matplotlib user, I certainly overlook its quirks in return for what it can do for me. But I think another interpretation is: If you use a complex, flexible library long enough, your recurring themes will eventually evolve into a library that "wraps" the original library.
I get your point, but disagree. I agree mpl is very powerful and you can do almost anything with it, but the biggest problem with mpl is the default behaviour for many things is just plain horrible. Take subplots, axis labels and ticks. By default pretty much any attempt will yield overlapping/obscured labels or way too much whitespace. Tight_layout helps a bit but in my experience you essentially have to manually tweak spacing and margins every time.

Similarly things like traditional x/y plots with a centre axis with arrows are much harder than they should be (it can be done but is really quite a bit of hassle).

And there are lots of other, similar issues. I suspect the OP is correct and it will be very difficult to replace mpl for producing publish quality plots (I think for interactive plots it's much easier and already done), despite it's shortcomings, because it is so powerful.

Try the new `constrained_layout=True`
I agree with your assessment. An important thing that you point out though, is that it takes regular use to get a good functional and flexible wrapper.

I occasionally (once every 4 months or so) have to create some plots for reports or analysis, and they are almost always very weird, dissimilar to previous plots. It always ends up being a huge pain, even if sometime in the past I've done something kind of like them (this is especially true for any kind of dynamic plots).

I've ended up building a pretty easy to modify plotting suite out of DearPyGui. I cannot recommend DPG enough, especially for high throughput or large scale plots. Immediate mode programming is a joy to work with, and it's pretty awesome being able to quickly toggle on and off any dataset in realtime.

Try seaborn. It's a decent wrapper.