167 points · by todsacerdoti · 3y ago · 42 comments
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.
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_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/constra...
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...
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).
This probably looks like grumbling or something, but it is sincerely a great help.
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.
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.
The only improvement could be to export the generated figures into excel so that we can make minor touchups manually.
I've tried all the rest. I've tried Julia. The tooling, my god, it is woeful. The famous Time To First Plot. I've tried Python. Doesn't hold a candle to Matlab for the ease with which you can manipulate matrices and vectors.
Matlab is far from perfect, but fuck it, it's an amazing tool for being productive.
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).
The rest of the language and the platform though? Awful.
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.