5 ms·
Matplotlib is still by far the most complicated library I have used in my fairly long career (10+ years). I worked with pieces of software for molecular modelin
by resiros 4y ago
Matplotlib is still by far the most complicated library I have used in my fairly long career (10+ years). I worked with pieces of software for molecular modeling with millions of lines of code that were easier to understand that matplotlib.
It's very powerful, I give them that, if you can think of a figure, it can do it. But you will probably spend an evening trying to make the labels not touch each other.
- valarauko 4y agoI hear you. I've been using matplotlib for about as long, and as a python first person still find the API baffling. I avoid it as far as I can, Seaborn where possible. I've been trying out Altair but unfortunately the figure types are relatively restricted, though the figure logic is a relative joy to use. These days, rather than struggling with the mess that is Python plotting, I drop into rpy2 and make the figure in R (so much easier and unusual figure types are covered).
- kevin_thibedeau 4y agoIt's baffling because it combines a Matlab style API with a Pythonic one using the same functions. If you know which is which it makes more sense.
- valarauko 4y agoI know that the matplotlib API combines two distinct styles, but it is little comfort when I'm struggling to wrangle a plot. To this day, I have to look up the API to do anything even slightly non-standard. Contrast with ggplot in R where it's a lot more straightforward. I've tried 'language of graphics' implementations in Python like Plotnine but they're just subtlety different enough from the ggplot implementation in ways that are annoying.
- _Wintermute 4y agoggplot2 is great until you want to do something slightly off-piste, then it's absolute madness, it has it's own OOP system because R didn't have enough of them already.
- valarauko 4y agoI think one of the major advantages of ggplot2 is the ecosystem - often somebody has already implemented the figure type I'm looking for as a ggplot2 extension. This is not to say that ggplot2 or R are capable of plots that can't be achieved in python or matplotlib. Unfortunately for the type of plots I'm usually trying to make, it's more clearly laid out in R rather than python. Python tends to offer me far more friction. For example, I'm unaware of any python package that simplifies creating annotated heatmaps - like pheatmap or complexheatmap can produce. I'm sure matplotlib can make them with enough skill, but it's not my forte. I find it easier to drop down into R and just call pheatmap.
- dima55 4y agoLook at gnuplotlib if you want another option. It's nicer in a whole lot of ways.
- rkp8000 4y agoJust in case anyone hasn't tried it before, the "tight_layout" keyword in matplotlib is a game changer. Instantiating a figure via e.g. "fig, axs = plt.subplots(1, 2, figsize=(6, 3), tight_layout=True)" automatically arranges the labels and subplot boundaries etc to not bump into each other. It doesn't work 100% of the time, but it usually does a pretty good job and has honestly saved me a ton of plotting headaches.
- cs702 4y agoIn my experience, `tight_layout` tends to work best after all objects have been drawn: fig, axs = plt.subplots(ncols=2, figsize=(6, 3)) fig.suptitle('Two Made-Up Plots') axs[0].plot(np.sinc(np.linspace(-5, 5))) axs[1].imshow(np.random.normal(size=(10, 10))) fig.tight_layout() # works really well here! More here: https://matplotlib.org/stable/tutorials/intermediate/tight_layout_guide.html https://matplotlib.org/stable/tutorials/intermediate/tight_l... You can also use `constrained_layout`, but in my experience it often doesn't work as well (e.g., the plots end up looking too cluttered for my taste), and also, `constrained_layout` can be noticeably slower (e.g., if you're drawing a large number of complex plots): https://matplotlib.org/stable/tutorials/intermediate/constrainedlayout_guide.html https://matplotlib.org/stable/tutorials/intermediate/constra...
- c-fe 4y agoIf tight_layout doesnt do the job, adding a ‘bbox_inches = tight’ may do it. I dont know why though.
- maxnoe 4y agoPlease don't recommended right layout anymore. There is a new, much better layouting engine since a few release you can get with `layout="constrained"`
- college_physics 4y agocomplexity you can wrap, seaborn style, trading some flexibility for an easier API. the real "competition" is, I believe, d3.js and visualization grammars built on top of SVG and d3 (vega, vega-lite) that allow amazing interactivity for non-technical users. you can integrate matplotlib nicely with, e.g., django to deliver server-rendered visuals, but its all static. this relegates matplotlib to exploratory modes (within an IDE or notebook) and production pipelines. this all might change with pyscript and a browser backend, remains to be seen.
- nxpnsv 4y agoPlotly is real competition and does html interactive stuff. I found it quite easy to use. I still prefer matplotlib though.
- college_physics 4y agoplotly offers multiple options (python, R, javascript). the weby stuff is done with plotly.js and uses d3.js underneath - https://github.com/plotly/plotly.js https://github.com/plotly/plotly.js
- bjourne 4y agoThanks for the link to Vega. That library/api is very impressive.
- charlieyu1 4y agoArcane syntax from matlab. And too many ways to do the same thing. Pretty much violates the zen of python.
- actinium226 4y agoWhat do you use instead?
- bee_rider 4y agoOne slightly redeeming feature about Matplotlib, in comparison to using matlab/octave plots or a spreadsheet, is that it is such a pain in the ass to use that I end up writing a full script rather than trying to manually tweak. So at least it is easy to reproduce my figures. This probably looks like grumbling or something, but it is sincerely a great help.
- d0mine 4y agoGithub Copilot manages to generate the boilerplate for matplotlib. The result can be evaluated easily just by looking at the plot. The code is mediocre at best but it allows to produce the desired plots quickly.
- sireat 4y ago10 years ago I loathed doing plots in Matplotlib. When Plotly offline version matured (circa v 4) I moved over. Lately, I've found that matplotlib is just fine for quick exploration when combined with Copilot prompts. Instead of spending 20 minutes staring at matplotlib documentation, I can be done in 2 minutes with a prompt or two. # my prompt can be something like get me horizontal bar chart of columns "foo" and "bar" from current dataframe. Rotate x axis ticks 45 degrees. Add y grid every 10 values. Use log scale for y. Add arrows with values for maximum values. Use emojis for markers. # result might require tiny bit of adjustment but will basically be there. # Full disclosure: I haven't tried the emoji prompt...
- antegamisou 4y agoMy experience has been the same. I always end up resorting to TiKZ/PGFPlots, which unironically has a steeper learning curve but rarely negatively surprises you once you get the hang of it.