You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
plt.plot does not plot anything with named arguments #12106
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
importmatplotlib.pyplotaspltimportnumpyasnpx=np.arange(0, 12, .5)
y=np.random.rand(*x.shape)
plt.plot(x, y) # works as expectedplt.plot(x=x, y=y) # shows empty plotplt.errorbar(x=x, y=y) # works as expected
Actual outcome
Expected outcome
or
Matplotlib version
Operating system: Windows 10x64
Matplotlib version: 2.2.3 (had the same issue with 2.2.2)
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.)
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.
If you are using a subplots, then you might want to consider the following -
''' The Figure in this case is 'fig' andinside 'fig' is the subplot 'ax'. '''fig, ax=plt.subplots(figsize=(12, 6))
# Plot the dataax.plot([1, 2, 3], [1, 2, 3])
plt.show()
Activity
anntzer commentedon 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 commentedon 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): Ifxand/oryare 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 commentedon 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 commentedon Sep 13, 2018
fwiw I'm also against fully kw-only mode (also as discussed in the linked thread).
jklymak commentedon Sep 13, 2018
I think that
plt.errorbar(x=x, y=y)works is more accidental than anything.anntzer commentedon Sep 13, 2018
Well, errorbar doesn't have a completely
stupidweird signature...jklymak commentedon 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 commentedon Sep 13, 2018
I agree it should error out.
rudrathegreat commentedon Nov 8, 2018
If you are using a subplots, then you might want to consider the following -
I hope that helped!
anntzer commentedon Jan 3, 2019
Actually a duplicate of #4059.