The problem with matplotlib has never been its capability. I consider its rendering backend and resulting image quality to be top-notch, and there are a billion options for you to customize.
That second part is the biggest problem with matplotlib: the imperative API cloned from Matlab is just terrible. The vast majority of matplotlib examples are rife with global states and overriding behavior (ever have to set font size twice to force it?) At first I thought that it's a bit clunky due to my inexperience, but no, the API is just that bad. See https://ryxcommar.com/2020/04/11/why-you-hate-matplotlib/
Now, I mean no hate to matplotlib, which is still a solid library. I appreciate their commitment to backward compatibility by keeping all those baggage, and I don't want them to yank them out, given that seaborn already mitigates most of the API problems, and Altair already brings enlightenment to Python plotting.
Now if only seaborn works with polars natively ...
The object-oriented API and its documentation have improved markedly over the years, I encourage you to give it a try. Most of the official documentation examples use it now. Yes, there are lots of examples out there using the pyplot interface still, but there is enough information on the OO API now that you can get by.
Personally I think pyplot is still a perfectly fine interface for just banging out quick data visualization without too much effort, but I find myself very quickly switching to the OO interface as soon as I want a little bit of control over what's going on.
There are still some lingering issues, like the interface discrepancy between scatter and other plotting methods, and the difficulty of making a nicely-formatted color bar. But it's really coming a long way since I started using it in ~2015, And in that time I've actually come to prefer it over both base R and ggplot2, which is what I started with originally.
I have much stronger complaints about Seaborn and he will never find me recommending it to anyone.
> The object-oriented API and its documentation have improved markedly over the years, I encourage you to give it a try. Most of the official documentation examples use it now. Yes, there are lots of examples out there using the pyplot interface still, but there is enough information on the OO API now that you can get by.
I agree. I used seaborn and matplotlib recently, and I was pleasantly surprised at both how much more consistent the API is and how much more comprehensive the documentation is. I dreaded using it at first but quickly became more accustomed.
> I have much stronger complaints about Seaborn and he will never find me recommending it to anyone.
Interesting, what are your pain points? For me, most of the time I start with seaborn, then modify the underlying matplotlib figure and axes for more customization; only rarely do I start with plt.subplots(). This gives me nice default styles while still allowing me to bend it to my will.
Can I suggest changing the title here to the article title?
"Best Python Chart Examples" It's a little less accusatory and I think a nicer representation of what it is
I’m particularly proud of this[1] figure I made using matplotlib for my PhD thesis. And yes, this is a single mpl figure and those are all individual axes. You do not want to see the source code.
What's weird is that I don't think I've ever heard any serious practitioner doubt its capabilities. The main complaints I hear are just annoyance with pyplot.
I recently started using Holoviews/Hvplot/Geoviews/Datashader for some big-ish data viz, and it's been mostly positive, but with some notable annoyances. The performance on big data is excellent. But I spent maybe two hours trying to figure out how to draw a damn regression line over my plot and I couldn't. Also hv.extension() seemed to break plain Matplotlib, whenever I tried to generate a plot after calling that function, I got an error about a non-interactive backend when trying to view a plot interactively, even when I selected an interactive backend explicitly.
I agree that R/ggplot is often more straightforward, but the main reason I (and most colleagues I've worked with) tend to use matplotlib is just a preference for python over R in general (to each their own though, that's not a debate I'm looking to start). If I'm doing data analysis in python already, it's a pain to export out just to plot in R. That said, it's definitely a steep learning curve, especially because it's something people usually learn on the fly instead of having any kind of formal instruction. I do think seaborn has really helped boost ease of entry wrt plotting in python at least.
That second part is the biggest problem with matplotlib: the imperative API cloned from Matlab is just terrible. The vast majority of matplotlib examples are rife with global states and overriding behavior (ever have to set font size twice to force it?) At first I thought that it's a bit clunky due to my inexperience, but no, the API is just that bad. See https://ryxcommar.com/2020/04/11/why-you-hate-matplotlib/
Now, I mean no hate to matplotlib, which is still a solid library. I appreciate their commitment to backward compatibility by keeping all those baggage, and I don't want them to yank them out, given that seaborn already mitigates most of the API problems, and Altair already brings enlightenment to Python plotting.
Now if only seaborn works with polars natively ...
Personally I think pyplot is still a perfectly fine interface for just banging out quick data visualization without too much effort, but I find myself very quickly switching to the OO interface as soon as I want a little bit of control over what's going on.
There are still some lingering issues, like the interface discrepancy between scatter and other plotting methods, and the difficulty of making a nicely-formatted color bar. But it's really coming a long way since I started using it in ~2015, And in that time I've actually come to prefer it over both base R and ggplot2, which is what I started with originally.
I have much stronger complaints about Seaborn and he will never find me recommending it to anyone.
I agree. I used seaborn and matplotlib recently, and I was pleasantly surprised at both how much more consistent the API is and how much more comprehensive the documentation is. I dreaded using it at first but quickly became more accustomed.
> I have much stronger complaints about Seaborn and he will never find me recommending it to anyone.
Interesting, what are your pain points? For me, most of the time I start with seaborn, then modify the underlying matplotlib figure and axes for more customization; only rarely do I start with plt.subplots(). This gives me nice default styles while still allowing me to bend it to my will.
(I took out "Best" though because that word doesn't matter and will provoke tedious objections about how no, these are not the best examples.)
[1] https://ibb.co/TLLBg37
Tired of hearing doubts about matplotlib's capabilities, I've curated and translated a collection of impressive charts using Python and matplotlib.
Explore them all with detailed tutorials and reproducible code at:
https://python-graph-gallery.com/best-python-chart-examples/
Having some level of abstraction on top of matplotlib is necessary if you don’t want to spend time tweaking every little thing.
Deleted Comment
My takeaway is that matplotlib may be a good alternative for specific cases where you need much more control.