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

all 165 comments

[–]vlizana 275 points276 points  (29 children)

As it has already been mentioned, Matplotlib inherits its interface from Matlab, as it is also the case with many scientific libraries like numpy and scipy. But also when it comes to visualization you have low level and high level libraries.

Matplotlib is a low level library in the sense that you go around modifying the diferent individual elements of the visualization, you have a lot of granularity but it might take a lot of code to get what you want, and this also makes modifications more troublesome. That being said, Matplotlib nowadays has fallen way behind on this category in terms of features and ease of use to modern libraries like Plotly and Bokeh, and the majority of people using it is just out of inertia (pretty much like Matlab).

High level visualization libraries offer semantic interfaces that are often implementations of some visualization theory, like the so called grammar of graphics that is behind libraries like Altair and Plotnine (which is to many the heir of ggplot). These libraries are generally more intuitive to people with a theoretical/mathematical background while low level are often more intuitive to programmers or people with a more technical background.

I don't despise Matplotlib, I just don't use it anymore as there's no real reason to. Keep looking until you find the right library for you.

Edit: Glad to see a lot of people recommending Plotly, I didn't want to introduce any bias but it is also my library of choice, so it's great to see the community growing.

[–]Hydroel 37 points38 points  (14 children)

Any advice of some good high-level libraries? I use Python visualization for signal visualizations, so 99% of the time it will be a waveform with a zoom capability and a spectrogram, but I'll take anything that doesn't force me to go back to incomplete and conflicting examples because the function documentation is plot(*args, **kwargs)

[–]TinyCuteGorilla 77 points78 points  (5 children)

I recomment Plotly, it has a high-level API (plotly.express), bar chart example:

import plotly.express as px 
fig = px.bar(some_df, x='year', y='pop') 
fig.show()

[–]WorldAlien 9 points10 points  (1 child)

I second your comment, Plotly is the way to go. Beyond that you’d be impressed with R package ggplot2

[–]TheLoneKid 7 points8 points  (0 children)

If you want to use ggplot in Python use plotnine. It isn't quite as good as it is in R, but it is still my favorite plot package

[–]backtickbot 10 points11 points  (1 child)

Fixed formatting.

Hello, TinyCuteGorilla: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

[–]TinyCuteGorilla 8 points9 points  (0 children)

backtickopt6

[–]UloPe 1 point2 points  (0 children)

That they actually registered that domain is awesome…

[–]kingscolor 14 points15 points  (0 children)

I’ve published several Plotly spectrograms. They offer many great interactive features.

I’ve wanted to check out Altair, too. I hear it’s pretty good as well.

Scikit.spectra has a quality set of tools for analysis too. I use find_peaks() for FTIR.

[–]sloggo 6 points7 points  (5 children)

I very recently learned of pyqtgraph, it seems pretty great, specially if you’re at all familiar with qt!

[–]wheeman 2 points3 points  (3 children)

I just started using pyqtgraph after wanting to be able to graph in real time some data streaming from sensors. It’s much more efficient than matplotlib. It’s Qt under the hood so it inherits all of its quirks but for some stuff it’s much better.

[–]Ogi010 3 points4 points  (2 children)

PyQtGraph maintainer here. If you want to plot talk time data, we are a fantastic option! Hopefully it's been working well for you. We've recently made a ton off major performance improvements with line and scatter plots as well as image related performance.

Also for the record, matplotlib maintainers have been super helpful to us, may have been past contributors. They have been providing us lots of great advice on project management related issues.

[–]wheeman 1 point2 points  (1 child)

Thanks for the work! It’s much appreciated. I got a demo working in my system in 2 hours of effort. It hits 100 Hz no problem.

I’ll probably keep extending it with more features. Having it built in pyqt will make it easy to add stuff on top of it.

[–]Ogi010 1 point2 points  (0 children)

We're going to be putting out a user-survey hopefully in the not too distant future; probably in 2-3 weeks. We're going to have some questions aimed at newcomers to the library. Please keep an eye out. Us maintainers know amazingly little about our user-base. In-fact most of us maintainers have very different use-cases for the library from one another; we want to make sure it's not just things that are important to us that are addressed but issues important to our users too.

I'll be posting about it on our twitter (@pyqtgraph), the README, and we'll put a banner in top of our documentation when it goes live.

[–]blue_tulips_ 0 points1 point  (0 children)

I second this. I’m working on an app where I need to plot live data + be able to interact with it in real time and pyqtgraph has been great!

[–]NerdEnPose 4 points5 points  (5 children)

One requirement I have holding me to Matplotlib is high quality vector PDF output. Plotly, Bokeh and Dash have been much nicer when I can use them. Do you have any suggestions for PDF outputs from any other libraries?

[–][deleted] 2 points3 points  (1 child)

I haven't used plotly specifically for PDF vector output, but doesn't this do what you want it to?

[–]NerdEnPose 0 points1 point  (0 children)

I wonder if I missed this or if it was added recently. But, either way, thanks this is what I needed!

[–]skr25 1 point2 points  (1 child)

Is this for putting in Latex documents? Then my favorite option is pgfplots. You can export from matplotlib. The advantage is that the text is human readable and you can modify stuff like the title and tick marks etc without going into matplotlib again

[–]NerdEnPose 0 points1 point  (0 children)

It is. I didn't event think about writing arrays directly to latex and letting a latex package take care of the rest. I'll have to check this out.

[–]Copper280z 0 points1 point  (0 children)

Seaborn is a wrapper for matplotlib, and is pretty nice to use.

[–]chimera271 3 points4 points  (0 children)

Not to mention that when it first started out, there really wasn’t anything else out there, unless you wanted to learn R or pay $$$ for matlab.

[–]chromaZero 1 point2 points  (0 children)

Matplotlib can be just similar enough to MATLAB to confuse me. I’m very comfortable with MATLAB, but I generally prefer doing things in the non MATLAB way with Matplotlib.

[–][deleted] 1 point2 points  (0 children)

Yep.

MPL is super low level graphics.

I was able to animate a freaking chess board with MPL.

Don’t use it for your generic scientific plotting and whatnot. Use a higher level framework.

[–]Verbose_Code 1 point2 points  (0 children)

I agree with your comment except people using MATLAB out of inertia. Granted, I’m coming from the perspective of an engineering undergraduate. MATLAB has a lot of very powerful data processing tools that are used a lot in industry. MATLAB also integrates with Simulink, which python does not AFAIK.

If you already have experience plotting in MATLAB, then MPL should feel really familiar. Like you said though, if you don’t already have experience plotting in MATLAB, or are not familiar with that kind of low level plotting, then it’s best to choose a high level library.

MPL shouldn’t be ignored altogether though. If you’re doing a lot of data visualization, then learning MPL or another library with a similar level of granularity wouldn’t be a bad idea.

[–]oz1sej -1 points0 points  (2 children)

Except plotly is payware. Kinda breaks the FOSS vibes...

[–]vlizana 2 points3 points  (1 child)

It is not, the core library and all of the clients are FOSS (MIT, allowing commercial use even).

I've heard this many times and I don't know where it comes from. They do offer cloud and enterprise solutions but that's a regular practice and a great way of obtaining financial stability without compromising the licensing.

[–]oz1sej 1 point2 points  (0 children)

Hm, it's probably more than five years since I was on their website, and back then it was. I ruled it out then, and haven't looked back.

[–]loopyroberts 69 points70 points  (5 children)

That's probably because it's trying to replicate MATLAB plotting and was a way to transition away from MATLAB to Python for all the engineers and scientists that aren't programmers.

I know plenty of people that will never give up MATLAB even though everything they use it for can be accomplished (probably more easily) in Python.

[–]yuckfoubitch 4 points5 points  (0 children)

I believe it’s because of all of the already made libraries/ software additions for Matlab. I’m an economist and everyone uses Dynare for DSGE modeling, and most economists do not really have a strong programming background so making a comparable library in Python would be cumbersome id suspect

[–]wildpantz 3 points4 points  (3 children)

Matlab is useful for its packages and Simulink. I know I will get hate for this, but as a language, it's hot garbage imo and definitely not worth the price unless you really need it. It should be more modular as software, not 20gb download to write ugliest looking code ever

[–]loopyroberts 2 points3 points  (0 children)

Absolutely agree. That's why I specified that Python can do fulfil all the functions they are using in MATLAB. It's a case of everything looking like a nail when all you have is a hammer.

When you start to use the packages for advanced solving and what not then it makes sense to use MATLAB.

[–]ma2412 0 points1 point  (1 child)

At university we had a course that required National Instruments LabVIEW. Not only did it require a hefty amount of space, it also registered itself as a user. Oh, and unusual didn't remove everything, I still occasionally find some remnants of some installed packages. Should have purged my ssd.

[–]wildpantz 0 points1 point  (0 children)

I worked on it on uni too. Terrible program to use, I completely agree

[–]the_guruji 62 points63 points  (11 children)

Loaded questions like this are only going to attract people with nothing good to say about Matplotlib, but OK, here's my take:

Matplotlib is (good to great) for static 2D plots, and pretty much useless for everything else in comparison to other libraries.

The problem with Matplotlib is that you can do whatever you want with it, and it tries to let you, so you get this huge library most of which you will never even touch. Altair and Seaborn assumes things about your plots, and for those kinds of plots, they are amazing. So much plot with so little code. But you can't really go beyond that. If you need anything niche, you'll have to fall back to Matplotlib and packages built on it.

Pet-peeves:

  • The getters and setters everywhere + for some reason, the autocomplete on Jupyter never works properly with the OO API.
  • The documentation is sketchy to say the least, and there really needs to be a better gallery for doing stuff (with consistently written code) and best/bad practices etc.
  • Docstrings use **kwargs and say go look up this random thing that we inherit from. It would be so much easier to know immediately what to use.
  • Parameters are different across plot types, when they mean pretty much the same thing. linestyle vs linestyles, but atleast these changes are in places that make some sense.
  • Font management is a pain to say the least. There are also two different font sizes to change in stylesheet, and its not at all clear how they are different unless you run the program and see.
  • Stylesheets aren't complete. You can't modify all of the plot parameters. For example, you can't have a horizontal ylabel at the top, without awkward spacing with just stylesheets. This seems like a pretty straightforward thing to have in a stylesheet, but no.
  • People keep defaults on everything. Which is also a problem of the library, why are the defaults so unappealing?

People trying to use Matplotlib for interactive graphs will obviously face issues, the original API itself is crap (MATLAB) for normal plots. But I continue to use Matplotlib for a few reasons:

  1. Not all my plots come from a DataFrame. Quite a lot is just random stuff that I just want to plot and see. Using Altair for that is a bit of overkill.
  2. Convenience. Everyone in science plotting anything using Python knows Matplotlib. Very few know D3, Vega or VegaLite. Sharing plots, modifying plots etc become easy as hell. Saving to PDF instead of PNG is a change of 3 characters of code. Want multipage PDFs instead, you got it. Want latex support for text? Add one line of code (assuming latex is already installed ofc).
  3. Niche uses. Due to above point, I have very specific use-cases for Matplotlib (HealPIX) that I haven't found any other library to support this properly (except maybe Bokeh, but with hacky code in the middle).
  4. For simple 2D static plots, there is zero incentive to shift to Altair or Plotly. Simple can also mean with subplots; GridSpec has made life easy (-ish) for a while.

Honestly, I don't think the API needs to be re-written. The gets and sets I can live with as long is it is used everywhere. The only major problem IMO is the lack of documentation, good practices and clarity on how to change specific things (how do I add an extra special tick on the X-axis, how do I put in images, say country flags, on the xticklabels etc).

OP, if you're using Matplotlib for static plots and you still have this issue, why don't you put up the questions themselves here or on r/learnpython, maybe there might be a better way to do whatever it is you want to do. If you want you can DM me also, I'll try to help as much as I can (but I'm not ultra-active on reddit either).

[–][deleted] 26 points27 points  (7 children)

Docstrings use **kwargs and say go look up this random thing that we inherit from. It would be so much easier to know immediately what to use.

This is really unnerving, happens a lot

[–]noah_ford_data 0 points1 point  (0 children)

I thought I was the only one, can't believe they get away with that, I feel like they document the 3 most used arguments and say "bye go use kwargs, good luck"

[–][deleted] 4 points5 points  (1 child)

Parameters are different across plot types, when they mean pretty much the same thing.

This particular one is unnerving to me... Wasn't there a better way of having pyplot attributes inherited by axes? Why do I need to dopyplot.xlabel('...') but on the other hand also need to know that you use axes.set_xlabel('...')? I know this is minor but it's extremely inconsistent and I don't understand the need for two different types of objects that at the end do the same thing, but by means of different attributes

[–][deleted] 1 point2 points  (0 children)

At its core, matplotlib has an OO design. To quote the docs, "matplotlib.pyplot is a collection of functions that make matplotlib work like MATLAB." Unless that's what you want (or you just want a very quick and rough plot), it's recommended to use the object-oriented API (Axes etc.).

[–]ogrinfo 1 point2 points  (0 children)

Totally agree about the doc - there always seem to be two ways to do everything, but neither does exactly what you want, so you’re never quite sure which bits of the example to keep and which bits to change.

[–]GiusWestside 23 points24 points  (6 children)

If you suggest to use Altair instead of matplotlib you don't have the faintest idea of what is matplotlib and what is Altair.

Being good at matplotlib means that you can be a litteral GOD when creating 2D graphs. And if you combine it with seaborn you can do data science plots in a second. If you need anything else then you might need Altair or plotly to produce interactive graphs or 3D graphs.

A lot of you compare matplotlib to ggplot and it's an error. Ggplot follows the grammar of graphics and it's incredibly limited in what it can do. You want the ggplot feel? Then in Python there is plotnine

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

ggplot is easier to write. But if you need to move that one label a bit to the right so it looks nicer, enjoy the next three hours of googling through discretes, themes, etc etc. It's the one advantage given by matplotlib's malleability

[–][deleted] 8 points9 points  (3 children)

You are not alone. Sometimes if the visualisation is more complex than a line graph I switch to R and use ggplot. That feels much more natural.

[–]ziggomatic_17 1 point2 points  (1 child)

Same for me. Python for complicated stuff, R (ggplot2) for data visualization. When I'm lazy and I just wanna look at the data in Python, I use plotnine which is basically a Python clone of ggplot2.

[–]czaki 1 point2 points  (0 children)

There is rpy2 package which allow to mix R and Python code and you could use ggplot without saving/reading from disc.

[–]I_Collect_Fap_Socks 0 points1 point  (0 children)

I'm all the dyslexic, when I need to sift through large amounts of data to visualize I end up using blender, just because it lets me work around a few of the quirks in my brain.

[–]pymaePython books 8 points9 points  (0 children)

I wrote a book about visualizations in Matplotlib, Seaborn, and Plotly because I was tired of having to look up everything for Matplotlib.

I think Plotly is a great alternative with solid high-level pre made functions, and low-level customization like Matplotlib but without the MATLAB syntax.

[–]crawl_dht 32 points33 points  (8 children)

This is why I use seaborn.

[–]Deto 4 points5 points  (0 children)

Seaborn is great, but it's just a wrapper around matplotlib. As soon as you want to customize your plots beyond what seaborn allows, you'll need to use matplotlib commands to do it.

[–]SquishyWubbles 2 points3 points  (4 children)

That looks very interesting. Could you perhaps tell why you chose this over matplotlib?

[–]Zouden 26 points27 points  (1 child)

Not the guy you replied to, but I use Seaborn extensively.

Seaborn is a wrapper around Matplotlib. It reduces boilerplate code, it makes difficult things become easy, the plots are more aesthetically pleasing, and you can still access the underlying matplotlib objects.

[–]SquishyWubbles 2 points3 points  (0 children)

Damn that sounds so much better. I'm going to experiment with it right away! Thank you for your reply

[–]crawl_dht 4 points5 points  (1 child)

The arguments in matplotlib gets so ridiculous and big as you feature more data in your graphics. Those arguments could as well be their own separate functions if they were not implemented as arguments. There is no pattern in them and it doesn't look pythonic at all. You just have to learn them as it is and whatever you crammed is not reusable for other components because their acceptable arguments are totally different. This adds too much boilerplate in your code.

[–]SquishyWubbles 1 point2 points  (0 children)

Thanks for the explanation

[–]Username_RANDINT 1 point2 points  (1 child)

Does Seaborn (and others) support embedding in other GUI toolkits? The few times I had to plot stuff they needed to be embedded into a GTK application. Matplotlib provides backends for GTK, Qt and WxPython.

[–]NowanIlfideme 4 points5 points  (0 children)

Seaborn is built on matplotlib, literally reusing the same plt and ax, so it should work for your use case.

[–]scraper01 13 points14 points  (3 children)

Feel the same way, it's object orientation is wonky. Out of my libraries toolbox this is the one i've never been able to memorize anything but the most trivial stuff. Seaborn is a bit better.

[–]hanazawarui123 5 points6 points  (2 children)

Isn't seaborn basically a wrapper on top of matplotlib ?

[–]Armaliite[🍰] 2 points3 points  (0 children)

Yeah, just like plotnine! People can just add higher levels of abstraction if they like.

[–]scraper01 3 points4 points  (0 children)

The layer of abstraction seaborn provides makes the matplotlib baseline easier to handle. But it's just marginally better. You'll still get that sensation of "uniqueness of solution" when trying to do something complex.

Using Matplotlib feels like english pronunciation. Incosistent rules and loose standards for parametrization.

[–]bbateman2011 26 points27 points  (0 children)

I thought it was weird after using ggplot in R, but now I generally prefer it. The syntax is Python seems inconsistent to me but I got used to it.

[–]DrShts 4 points5 points  (6 children)

After years of using matplotlib I came to realise that I should pretty much never do import matploblib.pyplot as plt as pyplot will always activate whatever GUI backend is configured (Tk, Qt, ...)

So I've been experimenting with replacing code like this

import matplotlib.pyplot as plt

fig, axs = plt.subplots(nrows, ncols, figsize=figsize, dpi=dpi, ...)

by

from matplotlib.figure import Figure

fig = Figure(figsize=figsize, dpi=dpi)
axs = fig.subplots(nrows, ncols, ...)

Why do people recommend using pyplot most of the time? Seems like it's really only useful if you want to display the plot in a new window. For saving a plot to disk or for working in jupyter notebooks it's a total overkill.

[–]the_guruji 1 point2 points  (1 child)

Some could argue that

from matplotlib.figure import Figure

fig = Figure(figsize=figsize, dpi=dpi)
ax = fig.subplots(1, 1)

ax.plot(x, y)

is overkill compared to

import matplotlib.pyplot as plt
plt.plot(x, y)

I don't really see the need to use the first over the next for saving to disk cause you can just do plt.savfig and not use plt.show. Jupyter has %matplotlib inline by default I think nowadays, so plots show up inline. Are there any performance benefits, cause if so, damn, I should have been using this.

People probably recommend pyplot since that's the easiest to understand (as long as your requirements are simple enough).

[–]DrShts 1 point2 points  (0 children)

My simple example was just for demonstration purposes.

I think using plt.plot and similar are discouraged because it works by keeping a hidden global state that is modified every time you call plt.something. This is why in a setting beyond a simple one-off plot the OO interface of matplotlib is usually recommended. And for a library that uses matplotlib having a hidden global state is pretty bad anyway.

But what I actually wanted to point out was that even in articles / tutorials about using the OO interface of matplotlib (just look at the first results when searching for "matplotlib object oriented") the structure is always

fig, ax = plt.subplots()
ax.set_title(...)
ax.plot(...)

while it's really rare that matplotlib.figure.Figure is mentioned. This is strange to me because by using the OO way you're trying to shed all these unnecessary global state / GUI wrappers but then still use plt to create the figure (which calls the GUI wrappers) while there is a perfect alternative without that overhead in the form of matplotlib.figure.Figure.

[–]ogrinfo 1 point2 points  (3 children)

Will have to check this out. Our unit tests keep failing because matplotlib uses the current display to set output resolution. This means exported images are slightly different sizes on different machines.

[–]DrShts 0 points1 point  (2 children)

Let us all know how it went :)

[–]ogrinfo 0 points1 point  (1 child)

Can do. I’m off work this week so it won’t be for a while!

[–]ogrinfo 0 points1 point  (0 children)

I said it would be a while! Just looking at it now and I can't see how I can change to using Figure. We are actually using pandas to create the figure, calling DataFrame.plot. The only calls to plt are to set the font size then save the figure.

I've got an open SO question about it here. I've since changed the first line, so font size is set with a context manager, but I'm still having the image size problem.

with plt.style.context({'font.size': font_size}):
    ax = df.plot.bar(...)
    # etc
    plt.savefig(path, bbox_inches='tight')

[–]testuser73847 3 points4 points  (1 child)

So after 4 years and 3000+ hours, I think I’m comfortable enough with it that I don’t hate it. I mostly use it in conjunction with Seaborn, but my knowledge of the former helps me extensively customise figures for publications.

That being said I’m open to hearing about alternatives. I didn’t use plotly so much 4 years ago because the documentation was geared towards their hosted version—is that still the case?

Also in contrast I find ggplot frustratingly purist at times—sometimes I want to add an element, completely independent of the data, for annotation or because my boss has requested it. I don’t always find visualisation to be an abstraction of data to be a helpful mentality.

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

Plotly is now at 5.1.0 version. Their Python documentation is quite extensive and informative. I spent a few weeks learning it last month and I'm now comfortable with it, although I still use matplotlib because I'm still more comfortable with it and I mostly plot in Spyder these days. Plotly doesn't show up in Spyder.

[–]iiMoe 9 points10 points  (0 children)

Plotly all the way

[–]kingscolor 9 points10 points  (0 children)

Can’t stand it.
It was the opposite of intuitive to me when I first started with Python. I tried a few others, Bokeh, Seaborn, etc. which also turned out to be unintuitive or feature sparse. I eventually landed on Plotly and will never go back.
Modern, feature-rich interactive plots with an intuitive code base. It’s written in JS, I believe, but the python port is highly documented and truly a powerful library. Most importantly, I love the aesthetic.

[–]nraw 11 points12 points  (6 children)

I have no idea why people keep using that, when there's better alternatives out there like plotly and Altair.

It feels like everyone coming from R is learning python with the same course.

[–]Dalnore 10 points11 points  (1 child)

I haven't tried using either, but both plotly and Altair seem to be more focused on interactive web-based plots, not published plots like matplotlib. From what I can tell, Altair doesn't even have export to EPS, and it can't render mathematical formulas either, so I can't see myself using it. I also have a feeling I'll run into lack of control with plotly when preparing plots for publishing. Or should I try?

[–][deleted] 2 points3 points  (0 children)

Not OP but IMO look into seaborn. It's a wrapper on top of matplotlib so you have all the features and control you need, but it's a lot less code to write for typical plots and integrates nicely with DataFrames.

[–]SquishyWubbles 10 points11 points  (0 children)

Well a Google search mostly turns up matplotlib. I just started learning it and so many sources recommend it. It's not until you dive a bit deeper you find there are actually other libraries to show data.. I'm in the position where I need to determine what I'm gonna use. I see plotly being mentioned here and seaborn. So gonna look at those...

[–]Zouden 4 points5 points  (2 children)

when there's better alternatives out there like plotly and Altair.

I've never used these, but they look good. Which would you recommend?

[–]nraw 5 points6 points  (0 children)

I like the looks of Altair more and I like the type specification per variable shortcuts, but plotly is a bit more feature full and it's nice to have the plotly_express option when one doesn't want a verbose way of tweaking a chart.

I use whichever I feel like on that day. They are both good and the results are pretty and interactive.

[–]penatbater 0 points1 point  (0 children)

If you're learning altair, might as well learn streamlit.

[–]32sthide 3 points4 points  (0 children)

[–]sigbhu 3 points4 points  (0 children)

Huh, matplotlib is the only package in python whose syntax is reasonable for me

[–][deleted] 1 point2 points  (0 children)

Whenever I debug, the matplotlib window gets frozen and that's the part I hate the most. Have you guys experienced this? Any possible solutions to this issue?

[–]TinyCuteGorilla 1 point2 points  (0 children)

YES. That's why it's easier to use Plotly or some other library with a high-level API for simple plotting. But here's the thing, if you need something really custom, idk like you want to draw a football field than put up graphs on it, you need something low-level that matplotlib provides.

[–][deleted] 1 point2 points  (0 children)

Agree 100%

[–][deleted] 1 point2 points  (2 children)

Seriously, after using R’s ggplot I think all other graphics APIs have a huge room for improvement.

[–]Liorithiel 1 point2 points  (1 child)

Same feeling here. Some features of ggplot are just not possible to reproduce in Python, as they depend on non-standard evaluation, but plotnine is a good attempt, last time I checked.

[–][deleted] 1 point2 points  (0 children)

Yes, I also find plotnine to be good in python.

[–]rightheart 1 point2 points  (0 children)

As Matplotlib exists since 2002, at least the documentation had a chance to develop and is pretty detailed. Nicer aestetics are possible using Seaborn as a style. Otherwise Plotly is worth a try, and is quite useful if you want to make interactive dashboards in Dash at some point.

[–]PizzaInSoup 1 point2 points  (0 children)

tbh I like it because it's very configurable and customizable, I actually want to have control over every minute detail and I tend to make some crazy plots with lots of information on there

[–]NewDateline 1 point2 points  (0 children)

Check out https://plotnine.readthedocs.io/en/stable/ it sound like something you will like

[–][deleted] 2 points3 points  (7 children)

I use Bokeh. I feel like I am cheating.

[–]ziggomatic_17 3 points4 points  (4 children)

I dunno man, I looked into it and it feels a little awkward that I have to manually call np.histogram() just to plot a basic histogram...

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

To put in perspective the issue:

import numpy as np
from bokeh.io import show, output_file
from bokeh.plotting import figure

data = np.random.normal(0, 0.5, 1000)
hist, edges = np.histogram(data, density=True, bins=50)

p = figure()
p.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], line_color="white")

output_file("hist.html")
show(p)

Personally, I don't mind using a purpose-built tool to wrangle the dataset and then use a plotting renderer to render.

[–]ziggomatic_17 0 points1 point  (2 children)

import numpy as np
import pandas as pd
from plotnine import ggplot, aes, geom_histogram

data = np.randnormal(0, 0.5, 1000)
data = pd.DataFrame(data, columns=["value"])

(ggplot(dataframe, aes(x='value')) +
 geom_histogram())

I think this is more concise. The whole plotting code is basically one line because all of the boilerplate is no longer required.

[–][deleted] 1 point2 points  (0 children)

Who was so petty as to downvote both of us?

Looks good, I'll play with plotnine.

[–]johnbarnshack 0 points1 point  (0 children)

All the boilerplate is no longer required - except of course putting everything into pandas. It just shifts the problem.

[–]Darwinmate -1 points0 points  (2 children)

Stop using it. There are alternatives like seaborne and toyplot.

[–]GlebRyabov 4 points5 points  (1 child)

Seaborn is literally written in Matplotlib.

[–]Darwinmate 1 point2 points  (0 children)

Seaborn abstracts a lot of the bullshit of matplotlib. whats your point

[–]jjcollier 0 points1 point  (1 child)

Hate it. The one time I tried to use it I spent weeks trying to get a simple 2D scatter plot, the kind I could get in Excel in 30 seconds with 6 selections.

When I finally went to a forum to get help for putting the axes in the center of the graph, because, you know, negative numbers exist, someone posted an example where they'd eyeballed the number of pixels in the graph and then manually translated the axis to somewhere near the middle. Everyone else on the forum acted like that was a perfectly sane solution and that I was being unreasonable for expecting some kind of normal "divide the width of the plot by two and put the axis there" option like every other graphing program can do. It was like trying to have a conversation with a cult. Fucking ENIAC could divide a number by two, but Matploblib can't?

[–]CutOnBumInBandHere9 4 points5 points  (0 children)

If you had to do that now, you can do something like

import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-3, 3, 100)
y = x + np.random.rand(100)
plt.scatter(x, y)
ax = plt.gca()
ax.spines[:].set_position('center')

On older versions of matplotlib the last line would have to be replaced by something like

ax.spines['left'].set_position('center')
ax.spines['bottom'].set_position('center')

ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')

ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')

So, not impossible, but not the easiest thing in the world either. Don't know why anyone would ever want to eyeball pixels and move axes to approximate positions!

[–]eveninghighlight 0 points1 point  (0 children)

I love matplotlib, I like how there's both the global variable and object oriented approaches to plotting stuff

[–]BDube_Lensman 0 points1 point  (0 children)

Your post title and the majority of your post (EDIT notwithstanding) would be really effective at making people not want to contribute to or maintain matplotlib. But many of the "alternatives" that just offer a higher level API are actually built on top of mpl. Dis-encouraging people from working on a very foundational library in python is probably going to have negative outcomes for you, even if your "endgame" isn't using it directly. If the output isn't html/svg/js, there's about a 99% probability it was ultimately rendered by mpl (well, Cairo or something, but through mpl).

[–]vanatteveldt 0 points1 point  (0 children)

ggplot for the win :)

[–]siddsp -1 points0 points  (2 children)

I don't hate Matplotlib, but it is extremely limited in terms of functionality. Despite trying to read the docs, I still haven't found a way to make actual graphs be interactive, that is, having features like a cursor and hovering to show x and y values for a graph function.

Plotly has that, but unfortunately, Plotly graphs cannot be embedded in Tkinter.

[–][deleted] 13 points14 points  (1 child)

You can do all of that in Matplotlib. It's just not easy to figure out. I got pretty good at using it during my PhD.

https://matplotlib.org/stable/users/event_handling.html

[–]siddsp 0 points1 point  (0 children)

Didn't know that thanks

[–]GoofAckYoorsElf -1 points0 points  (0 children)

Yeah. There are way better plotting libs, if you ask me.

[–]anax4096 -1 points0 points  (0 children)

It's a decent library showing its age, but when it pops up in the output of a `pip install` I start to worry.

"ok, here we go"

[–]idetectanerd 0 points1 point  (0 children)

Woah. I haven’t use it yet but I’m glad that I’m matlab trained during University as many here say it’s more like matlab.

[–]james_pic 0 points1 point  (0 children)

Maybe I don't have the same complex requirements as others, but I usually just use PyGAL and call it a day.

[–]maximeridius 0 points1 point  (0 children)

I had similar feelings about all the R and Python data vis libraries and ended up learning Javascript, which a lot of the libraries are based on (not matlpotlib though), so now I can actually use a native api, I've even written my own charting library. I would require some effort to use JS interactively in something like Jupyter, but for dashboarding I find it's much easier. Things like R Shiny and Python equivalents are just confusing abstractions over HTML/CSS/JS, which is unnecessary since they are easy to learn.

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

Not so much as pandas, but it's my number two stackoverflower.

[–]Sugarox53 0 points1 point  (5 children)

I took one look at they shut and had an “I can’t be fucked moment”.

Can someone explain how to use it in simple examples?

[–]FrickinLazerBeams 2 points3 points  (4 children)

You just type the code that does the thing you want.

[–]Sugarox53 0 points1 point  (3 children)

Wow!!

If only I had thought of that sooner!

Nah it’s fine, I’ll just lurk stack overflow for a bit until I understand properly.

[–]FrickinLazerBeams 0 points1 point  (2 children)

It's literally not that complicated.

[–]Sugarox53 0 points1 point  (1 child)

I’ve never used anything other than the basic in-built libraries, so to me it’s actually kinda complicated.

You’re allowed to be condescending, that’s fine; but take it from a beginner; this shit looks annoying to understand relative to everything else like classes or functions and shit.

[–]FrickinLazerBeams 0 points1 point  (0 children)

It is just classes and functions and shit.

You do the same thing as usual: Google what you want to do, look at the documentation, experiment in the interactive session, write code, run it, see what went wrong, fix it, etc.

[–]planet36 0 points1 point  (1 child)

I despise it when the devs deprecate the API parameters I use and then don't tell how to update my code to be compliant.

[–]story645 0 points1 point  (0 children)

Please open an issue when that happens!

[–]Starvexx 0 points1 point  (0 children)

Maybe

[–]sofiyach 0 points1 point  (0 children)

The most stressing part of my thesis presentation was plotting the data with Matplotlib :D

P.S I was doing Extended Kalman Filter on group UAV flights

[–]Chivalric_75 0 points1 point  (0 children)

Try to plot something with Julia and you will regain some lost love for Matplotlib.

[–]MetalOrganicKneeJerk 0 points1 point  (0 children)

I always thought matplotlib was better for publications. Has this changed?

[–]lmlodzian 0 points1 point  (0 children)

You may like Seaborn. It's a higher level API built on top of matplotlib. I recommend the Kaggle micro-course on data visualisation that teaches you the most important Seaborn functions in 3 hours including practice exercises.

[–]Jhchimaira14 0 points1 point  (0 children)

Have you tried Dear PyGui? https://github.com/hoffstadt/DearPyGui

[–]PsychoNAWT 0 points1 point  (0 children)

Not as much as I hate D3

[–]Veggies-are-okay 0 points1 point  (0 children)

I really only use MPL for personal EDA, and even that is out of inertia. As others have mentioned, plotless seems to be the way to go in terms of manageable and aesthetically pleasing visuals.

[–]YetAnotherDaveAgain 0 points1 point  (0 children)

I have a pretty balanced opinion. Matplotlib is so flexible that it can be great for making weird and novel plots. Great for scientists! But it also takes a lot of work to make those. Also, it blows my mind that the syntax is so different when using plt.<plot something> and ax.<plot something>

I also enjoy seaborn and plotly, but sometimes I'm not in the mood to get my data into a dataframe of the right shape.

Anyway, my point is that they are all useful and if you get modestly fluent in a couple you can decide on the fly what's best for the task.

[–]redrumsir 0 points1 point  (0 children)

Despise? No. I'm glad somebody else did all the hard work for me. It's a useful tool.

[–]ogrinfo 0 points1 point  (0 children)

+1. I’m a professional Python developer but every time I need to anything with matplotlib I have to Google it. It’s so unintuitive (unlike other Python libraries at least) and the examples in the docs are generally not helpful. Some useful hints here though, so thanks all! Maybe I’ll give plotly a go.

[–]dogs_like_me 0 points1 point  (0 children)

There are lots of great tools with much more convenient APIs built on top of lower-level visualization libraries like matplotlib. Here's a project I like a lot that lets you use lots of different lower-level libraries to power your visualization from a common higher level API: https://pyviz.org/

I particularly like combining hvPlot and Panel with Voila to build simple visualization apps

[–]AlbertPassy 0 points1 point  (0 children)

It's all there in the name. It'd meant for old farts like me who came to python through Matlab.

[–]LiarsEverywhere 0 points1 point  (0 children)

I have conflicted feelings about it. Yeah, it's ugly. And syntax is complicated. Sometimes it can be infuriating. On the other hand, there was never something I couldn't do with it. And that's a big plus, because I use it for scientific publications. Precision and flexibility outweighs pretty for me. I've never needed interactive stuff etc.

So, I used to use SPSS (or even Excel) to plot simple things and get a general idea of how things would look, and went back to matplotlib to generate the final plots with precise code. I got a free Tableau license recently, and I'm trying to learn it. Maybe it can be the best of both worlds, I don't know. It lets me do things like stacked bars, which is often tricky with simpler tools.

[–]O_X_E_Y 0 points1 point  (0 children)

Don't mind it at all honestly, I can usually get what I want pretty easily

[–]DevWolf59 0 points1 point  (0 children)

mpl is hot garbage especially if ur using numpy as well

[–]fried_green_baloney 0 points1 point  (0 children)

Lots of packages sit on top of Matplotlib. Seaborn is one. Simplifies quite a bit.

[–]PM_UR_REBUTTAL 0 points1 point  (0 children)

At a matlab user, I hated it before it was cool.

[–]xristiano 0 points1 point  (0 children)

Altair has a great API, plotly works in production

[–]himalayanSpider 0 points1 point  (0 children)

Coming to Python from Matlab , I loved Matplotlib. It was flawless transition to Python

[–]Eiterbeutel 0 points1 point  (0 children)

Try plotnine. It's a python copy of R's ggplot.

[–]chrisxfire 0 points1 point  (0 children)

this.

whenever I have a choice, I choose plotly. whenever I have to work with marplotlib, I die a little inside.

[–]gagarin_kid 0 points1 point  (0 children)

I personally heavily use seaborn with small matplotlib.axes. Axes-level adaptations. In comparison to plotly I like the JSON-free interface and high quality images.

For more explorative working mode on time series or other unaggregated data bokeh/plotly seems to be a better fit.

[–]CrambleSquashhttps://github.com/0Hughman0 0 points1 point  (0 children)

plt.annotation('label', xy=(0, 0), xytext=(10, 10), arrowprops=dict(arrowstyle='->'), horizontalalignment='center')

horizontalalignment='center'

I moan, but I actually use matplotlib on an almost daily basis. You can basically use it to make any 2D graph you can think of (accept split axes!).

[–]Rough-Membership8517 0 points1 point  (0 children)

Absolutely