Personally I find the style and whitespace defaults in matplotlib to be surprisingly displeasing. It always looks like "I just threw this together—I'll fix it later." Sure, you can fix it, but it's a huge fight.
PyX is a much better alternative. Like TeX, everything you make looks great.
The "I'll fix it later" aesthetic of matplotlib is addressed well by seaborn [1], which is built on top of matplotlib. Seaborn also works gracefully with Pandas. The killer feature for me of seaborn is "sns.despine()".
PyX is new to me, but it looks like it hasn't been updated in a while [2, 3].
Matplotlib is definitely a monolith, and it does seem like a huge fight to fix the style, but what is great is you can easily use some of its several predefined styles [0], define your own style sheets or customize specific style parameters through rcParams [1], or install third-party style sheets [2], so in the end the styling does seem much more manageable.
Python is my daily driver, but I briefly experimented with R and had a delightful experience with ggplot2. The ‘grammar of graphics’ was hard to leave behind when I switched back to Python, until I heard about Plotnine [1], which brings much of the same grammar and functionality to Python. It’s built on Matplotlib and a few other common libraries like Pandas.
The PyX's github repo [0] shows fairly low activity recently. The last commit was on November 21, 2021 (almost a year ago). I am curious whether PyX is in a maintenance mode?
I find using this library really confusing because of the two different APIs -matlplotlib.pyplot and the figures and axes of created plots.
Documentation and other peoples' code seems to jump between the two. It's a really good example of the downsides of having too many ways to do the same thing in the same library.
The comment you're replying to has a very specific concern: the difference between the OO and static APIs. The page you linked to didn't appear to address that, it's just a general tutorial. In fact, I can't even find where it mentions that aspect... It seems to assume you already know about that as a prerequisite.
You are right. It does not address this concern specifically, but if you follow this tutorial to learn this library, hopefully, you will not get to have this concern.
Regarding the different APIs, this page [1] from the documentation attempts to compare them and provide code that generates the same result using the the different APIs.
Figures and axis is the OOP interface, and what I always recommend.
Pyplot is a global namespace procedural interface similar to matlab. If you find an example online using pyplot, it’s easy to find the axis. counterpart. For example, plt.title() becomes axis.set_title().
> Figures and axis is the OOP interface, and what I always recommend.
No doubt, but half the time when I am looking online for how to do something off the beaten path, I find a documentation page or stackoverflow answer that (only) uses the other interface, and I have to flail about for a while to come up with the OOP equivalent.
Yep, I think the reference documentation is quite good. I always direct people to the quick start [0] and then look at the examples [1] to see how things are done. All examples have the plots and self-contained scripts so it's intuitive to search for what you want even if it's hard to describe or google.
I don't think that two ways to do something is too many. It's nice to be able to just throw a plot on the screen with plt.plot(), but it's also nice to have the extra control the figure/axes OO interface gives you. Matlab works the same way.
Matplotlib is very powerful and one can do great plots with it. I always find the process of creating great plots quite cumbersome and it involves a lot of trial and error, in particular when one has multiple subplots. I find proplot is a great wrapper that makes consistent plots much easier
the extensibility of matplotlib is simply incredible to me. I've always found the main limiting factor to be my imagination, once I wrap my head around what I want a plot to look like I know matplotlib will facilitate it. An absolute marvel, and a credit to the devs
This is what Copilot was made for. Auto-completing arcane incantations to render the correct font size for the legend, so I don’t have to look them up every time.
The one answer you got was that people don't care. I have another answer, which is that really sweating the details of visual interfaces, and handling all of the edge cases that users can discover, is one of the things that makes commercial software extremely costly to develop. Open source software has to focus on what can be done by the available time and effort of much smaller teams.
I love Matplotlib, but I have basically totally restyled it. I really don't like the default styling. Other than that, it is so much nicer to use than Mathematica's plotting tools...
It's very much one for journals. Here is one from my first paper https://ibb.co/373QMfV. Actually here I think the one on the left is matplotlib and the one on the right is Mathematica... I basically like a bold box and serif fonts
As a relative newcomer to python/data science I found it really surprising that Matplotlib seems favoured over Plotly. The Plotly API seems better designed and the output is far superior. Is matplotlib just favoured out of momentum or does it have advantages that I haven't found yet?
Personally I can't stand plotly. The only thing plotly does better is give you a nice interactive tooltip. While I wish matplotlib were better in that regard, it's usually not enough to get me to switch. Off the top of my head, these are the main pain points I have with plotly:
- It's slower than molasses in January for anything more than a few hundred data points. It regularly crashes VScode with the jupyter notebook plugin if I try to plot even 10 minutes of 100 hz data. That alone makes it a cheap toy. In gradschool, I was plotting hours of 25 kHz data in matlab with no problems.
- It's display mechanism is to show you plots is a web browser. I can't stand that. It's really slow to open a new browser tab for every plot. They don't re-use browser tabs, so after iterating for 10 minutes you have 20 open tabs.
- It's basically useless outside of a Jupyter notebook. If you try to use plotly outside of a jupyter notebook and want more than a single plot, good luck. At best you get different plots in different browser tabs, which is useless. Or you end up wasting time creating a web app just to view data.
- It's missing really basic functionality, like separate legends for different subplots.
- Maybe just personal preference, but I can't stand it's declarative interface. It leads to way more duplicated code and is too inflexible.
…also «old folks» like me know matplotlib already, there is existing code out there for matplotlib. Matplotlib fits into desktop software and print-quality plots - plotly is more about web plots. Libraries like pandas and seaborn use matplotlib. Really, there are quite a few reasons you might stick to it still.
But keep using plotly - keep visualizing data. It’s a superpower!
Momentum for a big part, and the libraries that build on top of matplotlib - like seaborn. And the default integrations with matplotlib (pandas, xarray, and a million others)
I do not have hard facts but bear with me. I always thought matplotlib interface/abstractions (as in, the code you write) felt shoehorned somehow. One day I tried the plotting in R lang and it was so natural. I felt like matplotlib was a somehow unnatural port of it.
It is one of those projects that work, but feels weird. I think of it as I think of pandas or celery.
PyX is a much better alternative. Like TeX, everything you make looks great.
edit for links:
https://pyx-project.org/examples/graphs/index.html
https://sourceforge.net/p/pyx/gallery/index/