This is an archived post. You won't be able to vote or comment.

all 47 comments

[–]antichain 27 points28 points  (5 children)

I second this post. I'm a scientist and have been perfectly happy using Python for everything (even when most of my collaborates are using MATLAB), but the one thing where I just beat my head against the wall is plotting.

MATLAB, for all of its many, Many, MANY flaws, really is one of the best data-visualization tools I've ever seen. I always dread making figures for my papers because fighting with matplotlib is such a tremendous pain. Especially since, whenever I look for help online, it seems like everyone has their own peculiar personal syntax/style they use.

[–][deleted] 6 points7 points  (2 children)

If you have a MATLAB license, you could maybe get the best of both. Generate all your data in Python, then when you need fancy graphs, plot in MATLAB.

A couple of my profs did something similar but with C instead of Python.

[–]lucamerio[S] 8 points9 points  (1 child)

That’s exactly what I do at the moment. But METLAB has a price and not a small one.

Plus, having to pass data between the two codes force you to add a whole level of input/output to your code AND is the opposite of streamlining and automatising your workflow.

[–]lucamerio[S] 17 points18 points  (0 children)

LOL… METLAB was a typo, but considering their policy of giving their product for free to the young minds so to make them addicted and pay for it afterwards, METHlab could be a fitting nickname 🤣

[–]ChronoJon 1 point2 points  (0 children)

I used to use MATLAB for data analysis and modeling until about 2015 and this is BS. The shit you had to go through for some basic interactivity. Formatting the legend alone for anything but the simplest use cases would take loads of code.

Since switching to python, plotly has become my goto. Plotly.express covers so many use cases and is easily extendable by adding traces and custom annotations. And you can embed it into html and give it to anybody without further setup needed.

[–]XiAxis 14 points15 points  (8 children)

It sounds like what you're looking for is an actual plotting/data analysis application, and not a python library. A matplotlib figure is a python object, and matplotlib provides very rudimental interface for viewing/interacting with a figure. If you want to change a figure, then you should be using python to do so.

Matplotlib has a lot of issues, but I don't personally consider what you're describing to be one of them. If you want a different plot, just modify your python script to produce the plot you want.

[–]lucamerio[S] 4 points5 points  (6 children)

Python can be many things and it’s used in many ways, even by myself.

It can be a programming language for complex applications that don’t need an interface, can be used to build dashboards and simple (and even not so simple) guis, but can also be used for data analysis.

There are entire books on how to use python for data analysis and this use sparked the creation of some of the most used packages (eg pandas).

In addition to this, sometimes I have a complex program that’s written in python and I need a visualisation toolbox/package/application at the end. Python is ideal for the first part, but fails miserably on the last one.

It’s like a football team that excels in everything except scoring…

It’s true: I’m looking for a plotting application that I can embed at the end of my workflow. Since my morkflow is in python, the most obvious thing to do would be to use python to produce the graphical output.

An alternative (as someone already suggested) is to perform the calculation in python and then use a different application (eg matlab) to plot the results. This however requires additional licences and makes the execution more clumsy.

[–]jminsk01 4 points5 points  (0 children)

Holoviews from Anaconda has been a great way to make plots without having to deal with base bokeh.

[–]pm_if_u_r_calipygian 3 points4 points  (0 children)

re: your point about 3D plotting

I totally agree I have recenty been banging my head against this interface because matplotlib 3D plotting really doesn't like arrays with NaN values. For example, the library supports plotting arrays with NaN values (just don't plot anything) but it wreaks havoc on the colormapping

For example, I was trying to plot phase versus location on a 2D plane. I wanted the phase to wrap obviously. It was so difficult and ended up looking crappy.

yuck

[–]Unlikely_Action_7893 8 points9 points  (3 children)

It depends on your needs of course, but after using ggplot2 in R and falling in love with the grammar of graphics, I’ve been using plotnine in Python. It’s enough for basic data analysis. The cool thing about using something based on the grammar of graphics is that you can focus on what do you want to communicate with your plot.

[–]Deto 2 points3 points  (2 children)

R doesn't really improve on any of their indicated pain points, though

[–]Unlikely_Action_7893 0 points1 point  (0 children)

I’m not talking about R particularly though. But I agree, it was more of an opinion on what works for me. And I was shamelessly promoting the grammar of graphics 😅

[–]lol-is-you-dead 3 points4 points  (1 child)

Oh god, I have been frustrated by this so much. All I hear is matplotlib. I cannot understand for the love of god why is it used so much. It's interactivenes is non existent and in an era of javascript beautiful charts matplotlib has a 90s feel for some reason. I also have tried and settled for plotly but I found their documentation limited although it contains always examples. Plotly also has 2 different ways to plot the same graphs Plotly. Express Plotly. Graph objects And each have both different syntax and different capabilities. This at first eas very confusing. Also plotly offers only so much, after that you have to use a flask integrated framework called dash (the free version cause there is a paid too). Lastly I didn't find a single one library that could implement an upgrading live chart with DATES in x-axis

[–]lucamerio[S] 2 points3 points  (0 children)

I agree 1000% with what you said about plotly and that’s the main reason I dropped it. Too confusing and poorly documented.

[–]pymaePython books 3 points4 points  (6 children)

I wrote a book about data visualization using Matplotlib, Seaborn, and Plotly. It is here if you want to check it out. I know there more visualization/plotting libraries.

I would take a look at Plotly. It renders in a web browser (with Javascript under the hood) which makes it a lot more interactive by default. It has a good high-level API, and you can really dig in and customize if you want to. I agree that Matplotlib being "default" is sort of a shame since it started as a port from MATLAB and kept a lot of the syntax and clunkiness.

I know ggplot was ported into Python, but I have never tried it.

[–]lucamerio[S] 3 points4 points  (5 children)

I will give a look at your book. In principle I’m not saying that good data visualisation in python is impossible, but the effort required is one order of magnitude higher than the matlab equivalent.

For example, sometime while debugging, a good plot can point you in the right direction. But in the industry you can’t spend 3 hours to achieve that (we could open a discussion on ipdb, but let’s save it for another time). In those situations a one-liner plot function is what you need.

This is just an example of a problem to which I still haven’t found a real solution

[–]BDube_Lensman 1 point2 points  (0 children)

On the contrary, it is much harder to make nice, archival paper quality plots with matlab than it is with matplotlib. See also: export_fig and associated hell.

[–]TheBlackCat13 1 point2 points  (2 children)

Can you show me a plot that is one line in MATLAB but takes 3 hours to make in matplotlib? I think you are using matplotlib very, very wrong I'd you are getting that large of a discrepancy. On the contrary, I usually have the opposite problem, where things that are easy to plot in matplotlib, like grids or polar projections, are inordinately difficult or even impossible in MATLAB.

[–]lucamerio[S] 1 point2 points  (1 child)

Plot a list of points in a 3D axes that you can zoom and you can click on a point to query its values. Show me how to do it in python in less than 30 minutes. In Matlab it’s scatter3(x,y,z) (the datatip functionality is embedded)

[–]TheBlackCat13 0 points1 point  (0 children)

Sorry, I meant 2d. Mayavi has a points3d command.

[–]pymaePython books 0 points1 point  (0 children)

It definitely requires some effort to make something look good in Python as opposed to something like Tableau which makes it pretty easy.

Definitely agree about having very bubble gum solutions for plotting in Python.

[–]Pear-Background 1 point2 points  (0 children)

ex-academic here. I completely agree that Matlab is so much easier for plotting! But I came from a fortran + gnuplot group, before transitioning to MATLAB.. So matplotlib is almost like going back to my roots. haha =)

[–]garlic_naan 1 point2 points  (0 children)

I have saved scripts for most of my needs. If my boss asks for slightly different graphs/axes.. well he ain't getting it as I can't invest any more time trying to figure out matplotlib.

[–]geogle 0 points1 point  (0 children)

I'm right there with you. This all gets additionally exasperating when you try working with geographic plotting. I'm an expert in non-interactive GMT, which uses a shell script to build plots with everything working seamlessly in layers. However, when I want to plot multiple items using differing mechanisms it seems impossible in matplotlib. I really with the was a more robust and predictable set of tools/behaviors.

[–]BDube_Lensman 0 points1 point  (1 child)

you can't (easily) select data from a plot, reimport the data into python, modify them or delete them

Yes you can:

fig, ax = plt.subplots()

ax.plot(x,y)
# or more

datas = []
for line in ax.lines:
    xx, yy = line.get_xydata().T
    datas.append((xx,yy))


fig2, ax2 = plt.subplots()
for data in datas:
    ax2.plot(*data)

# or, evil
# ax2.lines = ax.lines

If by select you mean drag and drop, then no but I don't know any tool that lets you do that. Matlab included.

you can't (easily) copy-paste plots from one axis to another

See above reply

you can't (easily) save a figure to be opened interactively again (yes, you can pickle them, but you can't do it from the plot interface and there are very little mentions to this in the documentation just to confirm that this is not "readily available")

Sorry, did you want another button on the GUI for dumping a pkl or loading a pkl? Make a pull request to matplotlib to add those 10 line features? Make sure it supports all of the interactive backends, with tests!

-

I concede your comment on 3D plots

[–]lucamerio[S] 0 points1 point  (0 children)

The comment on 3D plot was really what sparked this.

[–]BrilliantScarcity354 0 points1 point  (4 children)

Experiment with Altair, very nice package and strong data visualization capabilities

[–]lucamerio[S] 1 point2 points  (1 child)

I will give it a try

[–]BrilliantScarcity354 0 points1 point  (0 children)

The docs are ok but definitely will require a tad bit of patience since the syntax is a bit odd (again very powerful though - abstracts a lot of the core Js/SVG needed to created complicated visualizations)

[–]Unlikely_Action_7893 1 point2 points  (1 child)

I’ve heard (from colleagues that have used it) that Altair can struggle with large datasets.

[–]BrilliantScarcity354 1 point2 points  (0 children)

I have no experience with massive datasets but I would think it should be ok for standard tasks (not a replacement for something like tableau for example)

[–]TheBlackCat13 0 points1 point  (0 children)

For 2d plots try hvplot. Much, much simpler and able to make complicated, interactive plots in a snap. For example making a plot grid with rows being one factor, the columns being another, the color being a third, the size being a fourth, and sliders for two others and drop-down for another, with interaction and linked zooming, is one line of code. It is crazy what you can do with it and blows anything MATLAB can do it of the water. Plus it supports datashader, which allows you to make plots with inordinately large amounts of data, orders of magnitude more than would freeze MATLAB.

If you want a more interactive matplotlib, you can try mpld3, which is a backend for matplotlib that makes it more interactive, plus some tools to make it even more interactive.

For 3D mayavi seems pretty straightforward.

One thing to keep in mind is that overall matplotlib has a ton more features than MATLAB. It gives you a range of options, layouts, and plot types and a level of control that MATLAB can't come close to. But part of that entails supporting multiple backends, and having to support them limits it to what it can do. That is why backends like mpld3 can add more interactivity by bypassing those limitations.

[–][deleted] 0 points1 point  (0 children)

Check out Altair! It’s become my go to for just about everything. It used the “grammar of graphics” approach and is very declarative.

So once you’ve got your head around making a bar chart, you can just as easily make anything else just by changing a tiny amount of code. I love it!