-2

For example, when i use matplotlib as plt, a possible statement is like below:

plt.plot(x,y,color='blue')

so how can i get what arguments like 'color' i can pass to the 'plot' function, and what is the proper values for that argument?

Especially when i use some modules.

thanks for any answers.

Volan Hu
  • 1
  • 2
  • 2
    Have you tried reading the documentation? – Jonathon Reinhart Jan 19 '18 at 02:31
  • Have you even tried searching Google? The very first for `matplotlib` hit is the documentation! – Ken Y-N Jan 19 '18 at 02:39
  • Welcome to Stack Overflow, please review: https://stackoverflow.com/help/how-to-ask – Daniel Jan 19 '18 at 02:42
  • Tahnks for your answering. I guess Python should provide some tools to list those information like help() and inspect module. But i don't know the precise usage. e.g. help(plt.xlabel) doesn't give enough arguments details. what should i do to get those details other than reading documentation? – Volan Hu Jan 20 '18 at 07:38

1 Answers1

0

I'm a little disappointed that this post is being downvoted because I think it's a very legitimate question. In particular, I appreciate that you asked not what the answer was but instead how you could find it for yourself in the future.

Exploring Local Python Documentation

Python has a very robust built-in documentation system as well as a very active and supportive community. At any point in time, you can use the help function to examine a particular object that you want more information on - this will pull up the documentation for that object. In your example, you could do something like:

help(plt.plot)

to pull up the documentation for the matplotlib.pyplot.plot function. Outside of a running Python process, you can use the pydoc command line tool to read and explore that same documentation. Something like:

$ pydoc matplotlib.pyplot.plot

Running that in the shell will display the same documentation as the help command example.

Writing Documentation

As a good citizen of the Python ecosystem, you'll naturally want to document your own code. This is done pretty simply by adding a docstring to the top of a function, class, or module. Docstrings are denoted with a triple quotation mark """, seen in the examples below:

"""This module contains some example classes and functions"""

class MyClass(object):
    """MyClass does some things"""
    pass

def my_function(a):
    """Calculates the sum"""
    return(a)

There are many different documentation styles that people prefer, so what you choose is up to you. Though I would recommend the official docstring standards outlined in PEP 257.

Finding Online Resources

It's also often useful to take advantage of online documentation and resources. The official Python documentation includes all of the builtin documentation for the standard libraries as well as a tutorial for developers who are new to Python!

As it seems that you're relatively new to the ecosystem yourself, here's some more resources that you might find useful:

jtimmons
  • 376
  • 3
  • 7
  • Thank you very much. I tried help(plt.plot) and i do get useful help. But when i try 'help(plt.xlabel)', I didn't get enough arguments details(only 3 override arguments). How is this going? does it mean xlabel doesn't support other arguments? What should i do in this situation? I tried inspect module, too. only inspect.getmembers can give all arguments but with so many redundant message. I am new to python. Really thank you for answering such beginner's question so patiently. – Volan Hu Jan 20 '18 at 07:28