4 ms·
What's new in Matplotlib 3.7
- resiros 4y agoMatplotlib 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.
- cuteboy19 4y agoMatplotlib combines the ease of use of MATLAB with the engineering precision of ... MATLAB. At least the programmers won't feel like tearing their hair out at the lunacy of MATLAB. The only improvement could be to export the generated figures into excel so that we can make minor touchups manually.
- version_five 4y ago> minor touchups manually That's what I liked so much about matlab. You could generate figures programmatically and set the fonts and lines styles and whatnot, and then could just nudge stuff around in the figure if it wasn't how you wanted (plus retrieve that info).
- ok123456 4y agoThe figure editor is the only real thing I miss from matlab. That and the ability to rotate the axes of plots interactively. The rest of the language and the platform though? Awful.
- version_five 4y agoI mostly used matlab for fourier transforming data and plotting it, with some occasional image processing thrown in and a few "simulations" in the sense of calculating some function at a bunch of points. For all of that, I thought it was great. I saw people getting into make real applications, using the gui functionality and whatnot, it never felt like the right tool for something like that.
- ok123456 4y agoOutside of the core language of a glue for a bunch of numerical routines and stuff to plot them, it's a Frankenstein's monster. You never know if the script you send someone will work right, because everyone has different toolbox options, and everything is in the global namespace. It has some OOP features bolted on to it, but it always looked worse than Perl5. The core language is straight out of the mid-80s. The only real upgrade it got was it can finally broadcast matrix dimensions. Before that, you had people trying to 'vectorize' their code with 'repmat'. Despite all of its shortcomings, especially with packaging, I'll take scientific python over that any day.
- nicolapede 4y agoMatplotlib has been replaced by tikz [0] for most of the figures I need to generate (they would feed LaTeX docs anyway). [0] https://tikz.dev/ https://tikz.dev/
- eigenman 4y agoI've adapted the same work flow as well. It's really nice to have one script that generates data (often taking a few minutes or hours) and then another (in TeX) that configures display. That way when I recycle plots from papers into slides for a talk, I can reconfigure these easily.
- bjourne 4y agoTikz falls short when you have thousands of data points and/or need to do some scripting or filtering of the data. Scripting things is much nicer in Python than TeX.
- postexitus 4y agoI won't touch Matplotlib with a 6 yard stick when there is ggplot.
- patrick451 4y agoOf all the python plotting packages I have tried, matplotlib is still my favorite. A large part of this is that's one of the few that doesn't insist on using a web browoser. My only complaint with it is I wish the plots were more interactive. What I really want is the speed and API of matplotlib with the interactivity of plotly but without the web browser. I think matlab may be the only thing that comes close to that.
- vouaobrasil 4y agoI have tried so many plotting packages including Matplotlib but also others like R's base plotting, ggplot, Mathematica's plotting, etc. and I have to say I really dislike all of them. I am not sure why, but they all seem very counterintuitive compared to the way my mind things about plotting. This is especially true when it comes to formatting the plot. How I wish there were sane defaults for text size, etc. As much as I like Python for it's fairly clean and elegant syntax, I actually prefer making charts in Excel/OpenOffice. I would love it if someone made a hybrid model where you could put plotting into code, but yet once the basic plot was created, a GUI could be used to modify the appearance of the plot without remembering the syntax for all the graphical parameters. Maybe it could be a system where you run the code, and once the plot function is run in "interactive mode", an elegant GUI comes up and allows you to modify all the graphical parameters, and puts the required code into the plot function as parameters.
- greazy 4y agoHave you tried graphpad prism? I think that's the closest plotting software to a hybrid. There's also spss.
- saboot 4y agoI suppose I'm the minority of people that enjoy using Matplotlib. I dont want a 'simplified' interface, I want to be able to do nearly anything and matplotlib provides that to me.
- cycomanic 4y agoFor those who (like me) struggle to make consistent multigraph plots amongst other things I highly recommend proplot (https://proplot.readthedocs.io/en/stable/ https://proplot.readthedocs.io/en/stable/), a wrapper around matplotlib which takes away many of its pain points.
- kelsolaar 4y agoMatplotlib is awesome until you need to do advanced 3D plots where the lack of a proper 3D engine is becoming problematic. I had great hopes for Vispy but it seems like the original core developers moved back to their own plotting packages.