News for hackers. Stuff that matters.
Re:A new release for GNU Octave by kergonath on Sunday January 03, 2021 @06:08AM (#25621094)
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...

Re:A new release for GNU Octave by herogreen on Sunday January 03, 2021 @06:54AM (#25621267)
I 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).

Re:A new release for GNU Octave by enriquto on Sunday January 03, 2021 @06:26AM (#25621159)
> 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.

Re:A new release for GNU Octave by mkl on Sunday January 03, 2021 @06:36AM (#25621204)
Yes, 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).
Re:A new release for GNU Octave by leephillips on Sunday January 03, 2021 @08:45AM (#25621708)
You may have other reasons for preferring Matplotlib, but I don’t think anything allows more control over fine details or is more versitile than gnuplot.
Re:A new release for GNU Octave by mkl on Sunday January 03, 2021 @04:15PM (#25625311)
I've never had much use for Gnuplot. It can do lots of things, but in my experience, it's been easier to get what I want in other tools. Most of my plots are created in Python programs, Latex documents, or interactive web pages, where I use tools focused on that purpose and embed the code where it fits. For most of my one-off explorations there are better tools too.

If I'm using Matplotlib, I'm almost always plotting things calculated in Python, so all my data and variables are right there ready to go. I think the fine details are controllable in more programmatic ways than Gnuplot. I use other Python libraries when they're a better fit. Being Python and object oriented makes it easy to figure out how to do many things (e.g. autocomplete).

If I'm doing one-off throwaway plots, there are better and easier tools than Gnuplot: Desmos, GeoGebra.

If I'm making interactive demos, there are better tools than Gnuplot: Desmos, GeoGebra, JSXGraph, Jupyter.

If I'm plotting a function for a high-quality PDF document, TikZ gives me more control than Gnuplot, and makes it easy to make many plots with consistent (and changeable) style, though being a Latex-based tool it has limitations to go with its power. TikZ is great for diagrams too. Asymptote is more powerful than TikZ in some ways for this kind of thing, but often harder to use.

Re:A new release for GNU Octave by billfruit on Sunday January 03, 2021 @09:08AM (#25621826)
GNU plot syntax somehow feels less discoverable, less intuitive, one constantly needs to be looking at the docs while doing it, was my experience.
Re:A new release for GNU Octave by leephillips on Sunday January 03, 2021 @09:29AM (#25621951)
I can’t really disagree. It takes a while to come to grips with its concepts and language for settings. But basic plotting is concise and intuitive.

I was mainly commenting on its configurability. Gnuplot lets you (once you figure out how) control everything; for example, the exact shape of the arrowheads in a vector plot.

(The name is “gnuplot”; it’s not a GNU project.)

Re:A new release for GNU Octave by enriquto on Sunday January 03, 2021 @06:37AM (#25621210)
Sure, but none of these beats gnuplot's uber-elegant "plot sin(x)" syntax :)
Re:A new release for GNU Octave by mkl on Sunday January 03, 2021 @06:42AM (#25621231)
Sympy 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))
Re:A new release for GNU Octave by kergonath on Sunday January 03, 2021 @07:39AM (#25621428)
Yeah, Matplotlib is capable, but it’s heavy and verbose. It’s fine as an API, but the syntax gets in the way very quickly.

My use case is not a scratch pad with one plotting window; it’s dozens of windows with regressions and stuff. Each window is a completely different context; some of them are short lived and some of them are used for weeks. Using as many notebooks is very impractical. For example, seeing where one parameter is going in one calculations is trivial and quicker than starting a notebook and setting it up. Works transparently over ssh, too.

I am more or less fluent in Matplotlib, because I work with people who use it and I need to understand whatever the students are doing (and some of them use Python and some use R, which is a whole other discussion). I just dislike it and don’t use it much for my things. Ultimately, gnuplot’s syntax for regression and complex plots is much more concise.

I any case I think it’s good intellectual hygiene to use several tools regularly, lest you end up stuck in a way of thinking, so I encourage students to try others. It’s also good to have discussions about these things that don’t end up in holy wars; we need to be curious.

Re:A new release for GNU Octave by enriquto on Sunday January 03, 2021 @06:50AM (#25621252)
Can 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"
Re:A new release for GNU Octave by mkl on Sunday January 03, 2021 @06:51AM (#25621254)
You 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.
Re:A new release for GNU Octave by enriquto on Sunday January 03, 2021 @07:02AM (#25621291)
It'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.

Re:A new release for GNU Octave by mkl on Sunday January 03, 2021 @07:11AM (#25621328)
I 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.

Re:A new release for GNU Octave by abdullahkhalids on Sunday January 03, 2021 @07:51AM (#25621470)
If people have to reduce to this hack, why doesn't the language just declare every character string a symbolic variable by default, like Mathematica?
Re:A new release for GNU Octave by mkl on Sunday January 03, 2021 @08:02AM (#25621524)
Because the vast majority of Python programs aren't doing symbolic maths with Sympy. It's not a hack, and it's pretty trivial. I type "a," and press up, and run the line from my command history with all the letters in it. Sympy also has a submodule named abc you can import variables from, but I like defining them as real number variables so I don't get complex answers when they don't make sense.

Sympy is just a Python library, and one of the types it defines is symbolic maths variables, so you define Python variables just like with any other library, and then use them.

Re:A new release for GNU Octave by enriquto on Sunday January 03, 2021 @08:29AM (#25621648)
> Because the vast majority of Python programs aren't doing symbolic maths with Sympy.

And this, my friends, is why mathematicians will never feel at home using Python+libraries. Instead of having a programming environment ideally suited to the needs of math, you need to fit your math to the Procrustean bed of Python syntax.

Re:A new release for GNU Octave by abdullahkhalids on Sunday January 03, 2021 @11:13AM (#25622583)
That is what I wanted to say. The Python scientific ecosystem seems like it is written by programmers for scientists, while Matlab/Mathematica seem like they are written by scientists for scientists.
Re:A new release for GNU Octave by tomrod on Sunday January 03, 2021 @08:46AM (#25621716)
Eh, it's fine even despite your hyperbole. Applied mathematicians such as myself often use python without complaint. Setting up sympy takes no effort. Plus, #python on freenode.
Re:A new release for GNU Octave by williamstein on Sunday January 03, 2021 @08:45AM (#25621709)
SageMath solves these problems.
Re:A new release for GNU Octave by abdullahkhalids on Sunday January 03, 2021 @11:08AM (#25622549)
It does not. I tried to replicate some symbolic computation code I wrote during my PhD in Mathematica in SageMath, and I just failed to get anywhere despite weeks of trying. I don't think I don't understand SageMath enough.
Re:A new release for GNU Octave by tomrod on Sunday January 03, 2021 @08:46AM (#25621722)
Exactly. Grandparent commenter is complaining about resolved issues that the community worked out years ago.
Re:A new release for GNU Octave by nxpnsv on Sunday January 03, 2021 @08:12AM (#25621576)
One import statement is too much?
Re:A new release for GNU Octave by WoodenChair on Sunday January 03, 2021 @12:32PM (#25623245)
> 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.

Re:A new release for GNU Octave by joe_biden123 on Sunday January 03, 2021 @02:03PM (#25624089)
seaborn 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

Re:A new release for GNU Octave by Der_Einzige on Sunday January 03, 2021 @09:16AM (#25621873)
Matplotlib 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"
Re:A new release for GNU Octave by heyitsme on Sunday January 03, 2021 @01:32PM (#25623784)
could 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.
Re:A new release for GNU Octave by Der_Einzige on Sunday January 03, 2021 @11:10PM (#25627859)
See 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!
Re:A new release for GNU Octave by kergonath on Sunday January 03, 2021 @09:19AM (#25621891)
Never really looked into it; I'll have a closer look. What do you think is its strengths?
Re:A new release for GNU Octave by Der_Einzige on Sunday January 03, 2021 @09:20AM (#25621903)
For 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)

Re:A new release for GNU Octave by pletnes on Sunday January 03, 2021 @02:18PM (#25624257)
Bokeh 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)