Skip to content

plt.plot does not plot anything with named arguments #12106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
taxus13 opened this issue Sep 13, 2018 · 10 comments
Closed

plt.plot does not plot anything with named arguments #12106

taxus13 opened this issue Sep 13, 2018 · 10 comments

Comments

@taxus13
Copy link

taxus13 commented Sep 13, 2018

Bug report

Bug summary

When using named arguments for x and y, the plots created with plt.plot respectively ax.plot are keeping empty. plt.errorbar (or ax.errorbar) are producing the desired output (see code below).
The documentation shows that x and y are valid named arguments.

Code for reproduction

import matplotlib.pyplot as plt
import numpy as np

x = np.arange(0, 12, .5)
y = np.random.rand(*x.shape)
plt.plot(x, y) #  works as expected
plt.plot(x=x, y=y) # shows empty plot
plt.errorbar(x=x, y=y) # works as expected

Actual outcome
empty-diagram

Expected outcome
desired-diagram
or
desired-diagram2

Matplotlib version

  • Operating system: Windows 10x64
  • Matplotlib version: 2.2.3 (had the same issue with 2.2.2)
  • Matplotlib backend (print(matplotlib.get_backend())): 'module://ipykernel.pylab.backend_inline'
  • Python version: 3.6.2
  • Jupyter version (if applicable): 1.0.0 (Jupyter notebook 5.1.0rrc1)
  • Other libraries: numpy 1.14.5+mkl

Python was installed using WinPython, packages installed with pip.

@anntzer
Copy link
Contributor

anntzer commented Sep 13, 2018

I am not particularly sure that we want to support passing x and y as kwargs, see recent discussion on a similar topic at #11526.
(But if we decide we indeed don't, then we should make the documentation clear and error out when they are passed in as kwargs.)

@taxus13
Copy link
Author

taxus13 commented Sep 13, 2018

Thank you for your reply!
A warning message and a clear documentation would definitely help.

Another suggestion would be a 'keyword-only' mode for the plot function (and other affected methods, today I stumbled upon the same issue with loglog): If x and/or y are passed as kwargs, no positional arguments are allowed. Maybe this could be implemented as a layer around the current plot function, but I am sure if this breaks compatibility.

@phobson
Copy link
Member

phobson commented Sep 13, 2018

@taxus13 for an immediate work-around that's not writing your own function, seaborn might have you covered:
http://seaborn.pydata.org/tutorial/relational.html#relational-tutorial

@anntzer
Copy link
Contributor

anntzer commented Sep 13, 2018

fwiw I'm also against fully kw-only mode (also as discussed in the linked thread).

@jklymak
Copy link
Member

jklymak commented Sep 13, 2018

I think that plt.errorbar(x=x, y=y) works is more accidental than anything.

@anntzer
Copy link
Contributor

anntzer commented Sep 13, 2018

Well, errorbar doesn't have a completely stupid weird signature...

@jklymak
Copy link
Member

jklymak commented Sep 13, 2018

I guess it is a bit weird that this just doesn't plot anything, rather than give some sort of error.

@anntzer
Copy link
Contributor

anntzer commented Sep 13, 2018

I agree it should error out.

@jklymak jklymak added this to the v3.1 milestone Sep 13, 2018
@rudrathegreat
Copy link

If you are using a subplots, then you might want to consider the following -

''' The Figure in this case is 'fig' and
inside 'fig' is the subplot 'ax'. '''

fig, ax = plt.subplots(figsize=(12, 6))

# Plot the data

ax.plot([1, 2, 3], [1, 2, 3])
plt.show()

I hope that helped!

@anntzer
Copy link
Contributor

anntzer commented Jan 3, 2019

Actually a duplicate of #4059.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants