Skip to content

[MRG+2] Fix example for matplotlib 2.1 change#9897

Merged
lesteve merged 1 commit intoscikit-learn:masterfrom
lesteve:fix-for-matplotlib-2.1
Oct 10, 2017
Merged

[MRG+2] Fix example for matplotlib 2.1 change#9897
lesteve merged 1 commit intoscikit-learn:masterfrom
lesteve:fix-for-matplotlib-2.1

Conversation

@lesteve
Copy link
Copy Markdown
Member

@lesteve lesteve commented Oct 10, 2017

In matplotlib 2.1 legend has to be called with either 0, 2 or 3 non keywords arguments.

To reproduce the problem:

ipython examples/neural_networks/plot_mlp_training_curves.py

Stack-trace:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
~/dev/alt-scikit-learn/examples/neural_networks/plot_mlp_training_curves.py in <module>()
     86     plot_on_dataset(*data, ax=ax, name=name)
     87 
---> 88 fig.legend(ax.get_lines(), labels=labels, ncol=3, loc="upper center")
     89 plt.show()

/volatile/le243287/miniconda3/lib/python3.6/site-packages/matplotlib/figure.py in legend(self, *args, **kwargs)
   1518 
   1519         else:
-> 1520             raise TypeError('Invalid number of arguments passed to legend. '
   1521                             'Please specify either 0 args, 2 args '
   1522                             '(artist handles, figure labels) or 3 args '

TypeError: Invalid number of arguments passed to legend. Please specify either 0 args, 2 args (artist handles, figure labels) or 3 args (artist handles, figure labels, legend location)

@lesteve lesteve changed the title [MRG] Fix example for matplotlib 2.1 change. [MRG] Fix example for matplotlib 2.1 change Oct 10, 2017
@lesteve
Copy link
Copy Markdown
Member Author

lesteve commented Oct 10, 2017

Compare PR example to dev example

The plots look identical:

Plot from this PR:

Plot from dev doc:

@lesteve
Copy link
Copy Markdown
Member Author

lesteve commented Oct 10, 2017

@jnothman any objections fixing the example rather than pinning the matplotlib version on CircleCI?

@TomDLT TomDLT changed the title [MRG] Fix example for matplotlib 2.1 change [MRG+1] Fix example for matplotlib 2.1 change Oct 10, 2017
@agramfort agramfort changed the title [MRG+1] Fix example for matplotlib 2.1 change [MRG+2] Fix example for matplotlib 2.1 change Oct 10, 2017
@lesteve
Copy link
Copy Markdown
Member Author

lesteve commented Oct 10, 2017

OK self-merging then.

@lesteve lesteve merged commit 502261b into scikit-learn:master Oct 10, 2017
@lesteve lesteve deleted the fix-for-matplotlib-2.1 branch October 10, 2017 09:42
@jnothman
Copy link
Copy Markdown
Member

jnothman commented Oct 10, 2017 via email

@jnothman
Copy link
Copy Markdown
Member

jnothman commented Oct 10, 2017 via email

@lesteve
Copy link
Copy Markdown
Member Author

lesteve commented Oct 10, 2017

This is a bug in matplotlib. Is it our job to fix?

I could not find anything by quickly googling, maybe it is worth opening an issue if you think this is a bug. I guess from matplotlib 2.0.2 doc it looks like you could specify labels by keyword argument:
https://matplotlib.org/2.0.2/api/figure_api.html?highlight=legend#matplotlib.figure.Figure.legend

Having said that I think it is still worth fixing so that master is compatible with matplotlib 2.1.

@jnothman
Copy link
Copy Markdown
Member

jnothman commented Oct 10, 2017 via email

jnothman pushed a commit to jnothman/scikit-learn that referenced this pull request Oct 10, 2017
maskani-moh pushed a commit to maskani-moh/scikit-learn that referenced this pull request Nov 15, 2017
jwjohnson314 pushed a commit to jwjohnson314/scikit-learn that referenced this pull request Dec 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants