4 ms·
Agreed. I did not understand how terrible it is until I tried R's ggplot2.
by tryptophan 5y ago
Agreed. I did not understand how terrible it is until I tried R's ggplot2.
- krastanov 5y agoggplot and matplotlib have drastically different purposes. Ggplot is for statistical plots (see seaborn which is built on top of matplotlib for another style of statistical plots library). Matplotlib has multiple interfaces you can use and modern matplotlib code is very consistent and nice to use *if you need full control over your plots* (and it does way more than just statistical plots). The older matplotlib interfaces are indeed a bit of a mess, due to historical reasons. See bokeh (in python) and makie, gadfly, plots, and AlgebraOfGraphics (in julia) for yet more styles of making high level plots. But again, matplotlib targets users needing more control and less statistics (people build stats and other libraries on top of matplotlib though).
- bobbylarrybobby 5y agoIf you need full control over your plots, you should just d3, which an insanely sane interface compared to matplotlib
- krastanov 5y agoThat is a pretty terrible suggestion. D3 is wonderful, but it is just clunky to use for the engineering type of plots matplotlib excels at. And the learning curve for D3 is absolutely brutal compared to matplotlib. And D3 requires JavaScript (can you even get an arbitrary-DPI PNG or a high quality EPS/PDF with D3?)
- version_five 5y agoMatplotlib is like democracy, the worst option except all the other options. I do production quality plots for technical reports and matplotlib is the only suitable python library I've found that gives me the control I need. Like you say, there are lots of other libraries that combine stats (or other data analysis) and plotting. The paradigm I always use is to do the analysis separately, and plot the final result focusing on presentation and formatting. Matplotlib is the best I can find for this, despite the sometimes clunky interface. GNUplot is also good, but its easier to have a native python library. One more thing I'll say that had heavily biased me, I started off with Matlab, and I find that matplotlib is the closest to Matlab plotting, which is a lot of why I like it.
- petschge 5y agoI agree that it is nice to have a native python library, but I'd argue that the gnuplot interface is much better designed than matplotlib.
- jwilber 5y agoI’ve used both, have written dataviz libraries so know less than zero, and have never seen this distinction made nor agree with it. I wouldn’t even consider the two to have different purposes. Let alone “drastically” different. Drastically different api’s? Definitely. But purpose? No way.
- krastanov 5y agoThe distinction between "stats" plots and "science/engineering" plots is a pretty standard thing for every scientist I have worked with. Data for stats plots is usually represented well in a dataframe. Data for "science/engineering" plots does not always make sense as a dataframe. One is a small subset of the other. Maybe we are in different fields but for anyone I would be working with it is screamingly obvious that these two libraries have different goals. How would you even make cut-axis quiver plot over 3D isosurfaces and 2D contour projections with a bunch of insets for instance in ggplot? In python, matplotlib would be the obvious choice and it is better than pretty much all R or Julia options in terms of fidelity of control (Makie.jl is getting there and has a good interface). I do not think ggplot is at all capable of that, and it would be silly to do it with ggplot anyway given that the input data is not represented by a dataframe well.
- jwilber 5y ago“How would you even make [super specific plot]?” Ask on stack overflow, but a 10 second google shows that geom_quiver is a thing. From my view, the bigger distinction confounding your point is that most people doing non-dataframe oriented engineering work are using Matlab/Python/Julia over R. That would explain the preference for matplotlib, as the api was literally inspired from matlab (an inspiration shared by Julia as well). But I expect it’s more of a convenience thing than anything - why shove a specific part of a different language (tidyverse api for R) into your workflow when the existing solution already works enough? But R can work just as well, especially given the myriad of tertiary packages designed to transform your data into a “tidy” data frame (eg tidyr). In any case, if you’re goal is something complicated or bespoke, wrestling with matplotlib is probably the least friendly option available, but ggplot isn’t the best option either. You should just use JavaScript.
- bocklund 5y agoSeaborn is based on matplotlib and has basically the same semantics of matplotlib with better styling defaults and a wider API for different plots. For a ggplot grammar-of-graphics style library in Python, I really like Altair: https://altair-viz.github.io/ https://altair-viz.github.io/
- krastanov 5y agoThe semantics differ and the API is actually more restricted (and friendly), not wider, but yes, I agree it is not grammar of graphics. However, as much as I love the grammar of graphics, it is important to point out there are other good ways to make stat plots besides it. Seaborne, bokeh, statsplots.jl, algebraofgraphics.jl, and others.