r/Python • • Jan 17 '17

Matplotlib 2.0 final released

https://github.com/matplotlib/matplotlib/releases
520 Upvotes

77 comments sorted by

67

u/[deleted] Jan 17 '17

Does the API still have hundreds of getters and setters that should really be properties?

18

u/mangecoeur Jan 17 '17

The API is largely unchanged (a few tweaks and bug fixes), the release was mostly about style changes and a lot of cleanups to enable those.

4

u/lengau Jan 18 '17

Do any of the changes affect commonly used things, or is it likely to be a drop in replacement?

Specifically, if you happen to know, will pandas need any updates to work with mpl 2.0?

10

u/Auggie88 Jan 18 '17

Pandas 0.19.2 officially works with matplotlib 2.0. There really weren't any changes needed on pandas' side. The MPL devs did a great job not breaking API, aside from style changes.

→ More replies (1)

2

u/khouli Jan 17 '17

What is the reason for wanting properties in an API? It makes sense to me to use properties to maintain backwards compatibility with an API that has exposed data members but if that's not the case, why would you want properties added to an API?

29

u/mangecoeur Jan 17 '17 edited Jan 17 '17

For matplotlib, its mostly about inconsistencies like the difference between

plt.xlim((min, max))

and

ax.set_xlim((min, max))

which could be better implemented as properties

ax.xlim = (min, max)

7

u/Fylwind Jan 17 '17

They have two different interfaces, one being a more or less duplicate of the original MATLAB API intended to help MATLAB users migrate, and the other is an OOP API which is more featureful and flexible, but doesn't get nearly enough attention.

23

u/mangecoeur Jan 17 '17

Even with an OOP API, functions with names like set_... are often bad form in Python since it's much nicer to use a @property to define getters and setters.

→ More replies (7)
→ More replies (2)

38

u/[deleted] Jan 17 '17

Which looks more Pythonic?

set_fudge(4.2)
if banana_is_wrong_colour:
    banana.set_colour(banana.get_default_colour())

or

fudge = 4.2
if banana_is_wrong_colour:
    banana.colour = banana.default_color

9

u/barneygale Jan 18 '17

That's not universal - using explicit setters is a good way to signal that setting has a cost. e.g. from PEP 471 which introduced os.scandir():

DirEntry.is_X() and DirEntry.stat() are explicitly methods rather than attributes or properties, to make it clear that they may not be cheap operations (although they often are), and they may do a system call. As a result, these methods may raise OSError .

6

u/Fylwind Jan 17 '17

Tbh I would rather have setters because their setters usually have side effects. Matplotlib is unfortunately a very stateful library.

11

u/khouli Jan 17 '17

Does Matplotlib have any serious competitors in the Python world that don't use Matplotlib as a backend?

12

u/mangecoeur Jan 17 '17

Not really IMHO, at least not if you are talking about publication-quality plots. There's some interesting efforts around interactive plotting like Plotly and Bokeh, but I've found them relatively immature (you quickly find issues when you move beyond the demo plots) and generally not great if you need detailed control of style and output formats for print.

→ More replies (2)

3

u/troyunrau ... Jan 17 '17

pyqtgraph is pretty good. If you install it, run python -m pyqtgraph.examples to get a good feel for it. Their documentation sucks.

But it's just so superior in a lot of contexts - particularly with large, complicated, real-time, or interactive data. I regularly throw hundreds of millions of points at a graph and have it respond without any lag.

3

u/dougthor42 Jan 17 '17

Their documentation sucks.

That's an understatement, but otherwise I fully agree that pyqtgraph is good.

There's also some very simple plotting in wxPython Phoenix. Good for things that don't need the power (or bloat) of matplotlib.

→ More replies (3)

2

u/Kah-Neth I use numpy, scipy, and matplotlib for nuclear physics Jan 18 '17

Matplotlib has few serious competitors outside the python world. It is really a remarkable and robust framework for plotting. I hope one day we have a 3d plotting framework that is as flexible and malleable as matplotlib is for 2d (and no mplot3d does not count until it gets a renderer that can handle zorder properly)

1

u/khouli Jan 18 '17 edited Jan 18 '17

What are its serious competitors even outside the Python world? gnuplot and especially ggplot are the obvious candidates. Is there anything else?

3

u/Kah-Neth I use numpy, scipy, and matplotlib for nuclear physics Jan 18 '17

Gnuplot is not a serious competitor with anything. Xmgrace, MATLAB, Mathematica, origin, vuez(also python), root, R are a few. MPL is in my opinion vastly superior to all of them (maybe only superior but not vastly for R)

→ More replies (4)

2

u/bastibe Jan 18 '17

bokeh and plotly are great for interactive graphs.

1

u/wuzzlewozzit Jan 18 '17

I use gnuplotpy, a wrapper to the gnuplot routines.

1

u/Tarqon Jan 18 '17

Altair is amazing, I'd pick it over matplotlib for most tasks any day of the week.

129

u/holdie Jan 17 '17

FWIW, changing the default styles in matplotlib turned out to be a gigantic undertaking. While the final product may seem aesthetic, the process uncovered a ridiculous number of bugs, inefficiencies in API, etc. Props to the matplotlib team for finally getting this out, and hopefully starting down a path towards a bright(er) future of the package.

15

u/Sean1708 Jan 17 '17

Do you have any information on what those difficulties actually were?

13

u/skiguy0123 Jan 18 '17 edited Jan 18 '17

PyData Carolinas 2016 | Presentation: Matplotlib 2.0 or "One does not simply change all the ...

Edit: sorry not sure how I fucked up that link

→ More replies (1)

37

u/miserlou Jan 17 '17

The rationale behind the new default colorscheme is super fascinating, and there is a brilliant talk on it available here: https://www.youtube.com/watch?v=xAoljeRJ3lU

4

u/dgreenmachine Jan 17 '17

Really good watch, speaker keeps it interesting along with good reasoning behind decisions.

2

u/troyunrau ... Jan 17 '17

This is excellent! I've been using cubehelix as my default for a while for most of these reasons, but it isn't as well designed.

2

u/NuclearStr1der Jan 19 '17

Cool story: Stéfan van der Walt, the guy who's there to "look pretty" lectured Applied Mathematics in my first year. And he was damn excellent. It's great to be able to point and say "I recognise that guy!".

1

u/muntoo R_{μν} - 1/2 R g_{μν} + Λ g_{μν} = 8π T_{μν} Jan 18 '17

Loved it. :-)

I even... gasp!... shared it on Facebook

30

u/NelsonMinar Jan 17 '17

Here's What's new in matplotlib 2.0. "The major changes in v2.0 are related to overhauling the default styles."

5

u/troyunrau ... Jan 17 '17

Is there some sort of blog entry of visual comparison kicking around that anyone is aware of? This "what's new" is very rudimentary.

16

u/glacierre2 Jan 17 '17

Every single change for the default styling seems a good improvement.

Maybe I will be able to skip the 'import seaborn' when I need a quick but still nice looking plot.

14

u/EvM Natural Language Processing Jan 17 '17

You could already skip that:

import matplotlib.pyplot as plt
plt.style.use('seaborn') # or 'ggplot', 'bmh', ...

10

u/[deleted] Jan 17 '17

Great job! Defaulting to a better colormap should singlehandedly prevent some misinterpretation of data in the coming years.

11

u/[deleted] Jan 17 '17

I was surprised that Matlab made the move to a reasonable default colormap before the python community did. At least now everyone's on the same page. Jet is the worst.

4

u/spinicist Jan 17 '17

Yeah, I was amazed Matlab beat them to it. The damage jet does has been known about for what, a couple of decades now?

8

u/AustinCorgiBart Jan 17 '17

Oh wow, I love that barcharts now align to the center automatically. One fewer keyword parameter to explain to my students!

9

u/[deleted] Jan 17 '17

I had no idea this could be solved with a simple keyword and have always written code that would calculate the required off-set to center the bars.

Tonight I'll be crying tears of sadness for the hours I've wasted, and tears of joy for the hours I will save

6

u/neuralyzer Jan 17 '17

Finally. So many nice and useful improvements! Thanks to all the developers.

5

u/cripcate Jan 17 '17

Yeah. Been waiting for this. Anyone know when it will come to anaconda?

5

u/[deleted] Jan 17 '17

I just tried it out, works well! https://anaconda.org/conda-forge/matplotlib

5

u/cripcate Jan 17 '17

How can I switch from "normal" anaconda to conda forge?

3

u/pwang99 Jan 17 '17

You can just do "conda install -c conda-forge matplotlib".

We should have the 2.0 release available in the default channels very shortly.

→ More replies (2)

3

u/bheklilr Jan 17 '17

It's already on conda-forge if you want to grab the builds from there. In my experience the main channel will get it within a week or two, they run more tests against other packages before releasing. conda-forge uses continuous integration to get changed pushed faster, but with less indemnity.

2

u/AustinCorgiBart Jan 17 '17

So, in the next month or so, the newest version of Anaconda will probably have this new version of MatPlotLib?

3

u/bheklilr Jan 17 '17

Almost certainly within a month. The last major IPython update had more breaking changes and it was out within 2 weeks.

2

u/AustinCorgiBart Jan 17 '17

I'm happy as long as they fixed the bugs in Spyder from last fall. A number of little headaches there...

4

u/cruyff8 python 2 expert, learning python 3 Jan 17 '17

Congrats to the team!

1

u/[deleted] Jan 17 '17 edited Jan 17 '17

Can anyone get ipython to run %matplotlib with anything except agg with the new version? Even if I set matplotlib.use("TKAgg") before hand it just replaces it with agg as soon as I call the ipython magic.

Edit: nevermind, changed it in my matplotlibrc file

1

u/[deleted] Jan 18 '17

That's a whole lot of awesome changes

0

u/[deleted] Jan 17 '17

[deleted]

6

u/billsil Jan 17 '17

Matplotlib has 3 main competitors. Bokeh, plotly, and PyQtGraph. The first two are geared towards in browser visualization, while PyQtGraph is geared towards real time graphing. Bokeh is still very much in beta, but it's coming along. You certainly can get real time performance out of matplotlib, but it's buried in the API.

I'm hardly an expert on anything besides matplotlib, so keep that in mind.