Friction points in learning Matplotlib

This is a general catch all thread for users, especially those coming from different visualization tools, to talk about the friction points in migrating to Matplotlib.

I’m a physicist (here via your excellent Twitter outreach) working with people using matplotlib or bokeh so I’m trying to migrate from my old tools - I’ve been using CERN ROOT, either in their sort of C interface or via pyroot, for twenty years. There’s a lot of statistical support there for fitting, but ok, I can grab stuff from scipy. I’m not a very enthusiastic migrator, but here are a couple of things that bug me.

I have trouble remembering scatter vs hist vs plot vs hist2d; I don’t know how to make a profile. In ROOT I’m at least inheriting from the same class, and a 2d plot is a scatter plot or a profile plot based on putting something like “scatter=True” or “profile” in the constructor. I use the same syntax or actual code to access info from these objects. In matplotlib I don’t know - too lazy no doubt to RTFM - where the object is, or what the class structure is. I see a lot of “n, bins, patches = plt.hist(…)” - what is that? Why don’t I do h = plt.hist(…) and bins = h.getBins() or something? Also I’m constantly having trouble with in my scripts. And when I do something dumb like plot two histos on a canvas with different axes I get something hard to interpret not an error. Oh, and I wish I could make a 2d hist with a (2, n) numpy array instead of destacking.

1 Like

@rilkefan join us at we’re trying to simplify so of the common hep plotting things with matplotlib. So far not much 2d plots, but we’d be happy to hear other missing methods. Part of the trouble with transition from ROOT is separating the histogram class/object from which holds the data from the visualization which is what matplotlib does. plt.hist() returns a numpy histogram which is really just a tuple of values, bins and then it returns the plotted patches like the rest of mpl functions. It’s kind of a frankenstein function.

There is ongoing work on a proper python histogram object here which should improve things a bit in the near future

1 Like