4 ms·
I use Matlab-likes (actually Scilab rather than Octave) for one offs and interactive use. That’s usually playing with a dataset, test some analysis techniques,
by kergonath 6y ago
I use Matlab-likes (actually Scilab rather than Octave) for one offs and interactive use. That’s usually playing with a dataset, test some analysis techniques, quick regressions, solving linear equations systems, this sort of things. I hate having to set up the whole machinery when doing this in Python. Also, the general-purpose nature of Python gets in the way, whereas the Matlab-like syntax is very focused and much less cumbersome. This does not matter much in a script, but is a pain for interactive use. On the other hand, Matlab is terrible to write scripts, with its inconsistencies and its almost-Fortran-but-weirder syntax.
Once the pipeline is set, Python is for scripts that need to be run more than about a dozen times, or need to be run on several datasets, or for things that need to be reproduced exactly (like stuff that goes into a paper). I also use it to prepare datasets from large numbers of calculations where the useful results need to be gathered from dozens/hundreds of files in a more or less complex file structure, often on different computers, with the occasional pass with some post-processing tools.
I really dislike Matplotlib, so rendering is done in something else, usually gnuplot.
That’s for my stuff (mostly atomic-scale modelling and quantum chemistry in materials science), it might be different for other use cases...
- enriquto 6y ago> I really dislike Matplotlib, so rendering is done in something else, usually gnuplot. This! My biggest gripe against Python numerical stuff was matplotlib, until I realized that it is an entirely optional component of the stack, and you can plot by other, much saner means.
- mkl 6y agoYes, there are many good alternatives. Seaborn, Plotly, and many more. I still use Matplotlib for most things (with the OO API), as I can control its fine details and it's more versatile. For non-graph visual things that I could use Matplotlib for, I've been generating SVGs and displaying them directly in Jupyter notebooks (with Cairo is one option, but just directly is pretty easy too).
- enriquto 6y agoSure, but none of these beats gnuplot's uber-elegant "plot sin(x)" syntax :)
- mkl 6y agoSympy can do that: plot(sin(x)) This of course works with other symbolic manipulation: plot(sin(x).diff()) plot(sin(x).subs(x, x**2))
- enriquto 6y agoCan you show the complete code for these snippets to work? I tried import sympy sympy.plot(sympy.sin(x)) and it says "NameError: name 'x' is not defined"
- mkl 6y agoYou need to tell Python that you want a symbolic variable named x: from sympy import * x = symbols('x') plot(sin(x)) symbols is sympy.symbols.
- enriquto 6y agoIt's not particularly elegant, is it? You just want to plot the sine function, but first you have to import libraries, declare symbols (with a scary correspondence between strings and variable names), and finally plot the damn function.
- mkl 6y agoI literally always have a Jupyter QtConsole open with one tab having Sympy loaded, and every single letter variable defined as a symbolic variable, and another tab with numpy; this is my constant daily-use calculator. In that context, it really is just "plot(sin(x))". It's not really anything more than having a terminal open with Gnuplot running, and no less elegant. Edit: plus, if I'm plotting with Sympy it's almost certainly something I've calculated symbolically with Sympy, so everything is defined and ready, and it's much more elegant than switching to a separate program. For a one-off "what does function look like?" question, both these tools are far too clunky, and I'd use Desmos or GeoGebra.
- herogreen 6y agoI really like matplotlib: while it is not intuitive and the documentation is sometimes lacking, there are a lot of examples online and stackoverflow answers all my questions. That said I may use matplotlib much less than you do (I used it a lot when I was a student, now maybe 6 times a year).
- Der_Einzige 6y agoMatplotlib is terrible (once you get to the point that you need to do non trivial things with it), that's why you use the excellent plotting library for python called "Bokeh"
- kergonath 6y agoNever really looked into it; I'll have a closer look. What do you think is its strengths?
- Der_Einzige 6y agoFor me? I care mainly about 2D and 3D scatter plots of large datasets. The GPU acceleration and automatic subsampling means that animated or interactive scatter plots of large amounts of data (for me it's language vectors) is super easy and fast rather than slow and crappy with matplotlib... (I think matplotlib has an openGL backend that slightly improves but doesn't fix the issues with matplotlibs handling of large datasets)
- pletnes 6y agoBokeh is also made to create embeddable, interactive plots for html/js. You can create quite sophisticated graphics with it from the backend alone. (We use it for web apps at $WORK)
- heyitsme 6y agocould you give an example of an "non-trivial" thing you're talking about (i.e a few lines of code)? And how you solve it with "Bokeh"? I agree that matplotlib's functional interface is somewhat messy, but that is somewhat historical, and stems from wanting to mimic how matlab works. I personally find matplotlib's OO interface both very powerful, and somewhat intuitive, once one gets a hang of it, hence I'm curious of specific cases where it fails for you.
- Der_Einzige 6y agoSee my other post in this comment chain. Matplotlib is not good with handling large (e.g. more than 100K) datapoints in 2D or 3D if you want interactivity or animations. Bokeh handles it like a champ!
- WoodenChair 6y ago> I really dislike Matplotlib, so rendering is done in something else, usually gnuplot. I'm glad I'm not alone. I was starting to feel crazy—how can something with this bad an API (Matplotlib) be this popular in the Python ecosystem which is known for its lack of verbosity and clarity? How can it be integrated with every other package instead of some sane alternative? I tried Seaborn (a wrapper effectively), and it is way better for doing basic plots. But as soon as you get beyond that you're back in arcane Matplotlib territory. The best thing I could have done would have been to ignore its integrations and start with a better plotting API to begin with. The little bit of extra integration effort would have been worth avoiding Matplotlib. And there are several alternatives in the Python landscape. No offense to the authors—it's clear they've done a lot of great work. But I think they got stuck with a bad API that they started with and it became so common-place that they were forced to continually be backwards compatible with something that really needed an overhaul.
- joe_biden123 6y agoseaborn is nice because it let's you do plots with one line that would take a page of code in basic matplotlib, but if you need to change one specific thing it might become really hard. I honestly moved on to gui based plotting programs like grace or veusz, there's just a button for the things you want to do