3 ms·
> I really dislike Matplotlib, so rendering is done in something else, usually gnuplot. This! My biggest gripe against Python numerical stuff was matplotlib,
by 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.
- abdullahkhalids 6y agoIf people have to reduce to this hack, why doesn't the language just declare every character string a symbolic variable by default, like Mathematica?
- mkl 6y agoBecause 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.
- 6y ago
- kergonath 6y agoYeah, 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.
- leephillips 6y agoYou 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.
- mkl 6y agoI'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.
- billfruit 6y agoGNU plot syntax somehow feels less discoverable, less intuitive, one constantly needs to be looking at the docs while doing it, was my experience.
- leephillips 6y agoI 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.)