Skip to content

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

Closed

Description

@taxus13

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.

Activity

  1. anntzer commented on Sep 13, 2018

    @anntzer
    Contributor

    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.)

  2. taxus13 commented on Sep 13, 2018

    @taxus13
    Author

    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.

  3. phobson commented on Sep 13, 2018

    @phobson
    Member

    @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

  4. anntzer commented on Sep 13, 2018

    @anntzer
    Contributor

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

  5. jklymak commented on Sep 13, 2018

    @jklymak
    Member

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

  6. anntzer commented on Sep 13, 2018

    @anntzer
    Contributor

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

  7. jklymak commented on Sep 13, 2018

    @jklymak
    Member

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

  8. anntzer commented on Sep 13, 2018

    @anntzer
    Contributor

    I agree it should error out.

  9. added this to the v3.1 milestone on Sep 13, 2018
  10. rudrathegreat commented on Nov 8, 2018

    @rudrathegreat

    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!

  11. anntzer commented on Jan 3, 2019

    @anntzer
    Contributor

    Actually a duplicate of #4059.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions