-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
improve docstring of Axes.plot #10190
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
Conversation
For easier review: Old docs: New docs:
|
lib/matplotlib/axes/_axes.py
Outdated
optional format string. For example, each of the following is | ||
legal:: | ||
Plot lines and/or a series of markers. This is also known as line plot | ||
or XY (scatter) plot respectively. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the word 'scatter' here dangerous as we also have a scatter
method. I worry about compounding the confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, the confusion is inherent in the naming of the methods. The general notion of scatter plot in its basic form is what we're doing here. That's why I added the sentence. I've also added the scatter method in the See Also section.
IMO doing both is as good as we can get to prevent confusion. If you find it beneficial, one could add an additional sentence: "Note that matplotlib also offers a scatter method which can additionally change marker properties per data." But that may be overdoing it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need the use of "scatter" in here either. "Plot y versus x as lines and/or markers" is how I'd phrase this.
lib/matplotlib/axes/_axes.py
Outdated
`pandas.DataFame` or a structured numpy array. | ||
|
||
.. note:: | ||
The signature ``plot(xlabel, ylabel, data=obj)`` without a format |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not true. If it is ambiguous it will warn, but
In [27]: plt.plot('x', 'bob', data={'x': range(5), 'bob': range(5)})
Out[27]: [<matplotlib.lines.Line2D at 0x7f621f4fe898>]
works as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, but I didn't want to advertise a signature that issues a warning and suggests to change the code:
plt.plot('x', 'y', data={'x': range(5), 'y': range(5)})
RuntimeWarning: Second argument 'y' is ambiguous: could be a color spec but is in data. Using as data.
Either rename the entry in data or use three arguments to plot.
There was an even more obscure explaination, which frankly I do not understand:
If used with labeled data, make sure that the color spec is not included as an element in data, as otherwise the last case plot("v","r", data={"v":..., "r":...) can be interpreted as the first case which would do plot(v, r) using the default line style and color.
I recon this has something to do with plot(ylabel, fmt, data=data)
vs. plot(xlabel, ylabel, data=data
), which is not distinguishable. Where as plot(y, fmt)
vs. plot(x, y)
is implicitly distinguished by the data type of the second argument.
To me that's a symptom of the limited sanity of the API. When a call works with a label 'bob' but not with a label 'y', there's too much magic going on in the background.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is only ambiguous when the keys in data
are also valid 'fmt' strings (and in that case we break the ambiguity in favor of pulling from data
).
It's not magic, it's attempts to 'do what I mean' which is worse ;)
I am not a fan of this re-origination. I think there is value in having that block of call signatures at the top. I also do not like the "Basic" vs "MATLAB" vs "Labeled data" distinctions. Between the first two, the only diffrenece is using explicit keywords or a shorthand string notation for specifying styles (which can be mixed, Sorry for being negative. You have been doing great work recently! |
Thanks for your feedback. I'm happy to work out how to improve the docs together with you. I will give my motivations and then we can see how to processed. Sorry if I'm having some harsh words on the API and the docs here and in the comments above. It's been given me really a hard time and that may shine through. Neverteless, I'm committed to make it as accessible for the user as possible. I'm not claiming that my proposal the definitive best version.
I consider the following changes essential:
What might not be essential:
|
👍 to adding the numpydoc headers. The
This is the MATLAB inspired API. No matter how painful it is, it is something we can not break, there is way too much code that depends on it. My understanding of positional arg parsing is that it pulls off arguments of I suspect a flow-chart will help... The |
Ok, many of the issues do only arise if there is more than one dataset. What about first describing the one-dataset case and later the changes for multiple data? The signature could be:
or a little less precise:
That's not an exact signature and needs some explanation in the text, but it's probably instructive enough, so that the users recognize the basic structure and can use it for simple examples without having to understand all the edge cases. I'd rather not put a flowchart. It might be the correct way to exactly describe the signature. However, it's quite intimidating having to read and understand an algorithm just to know which parameters I have to pass in which order to get a simple plot. Though not part of a strictly valid python signature, the |
1375f72
to
e6503b4
Compare
Here we go again. I've used my above suggestion for signature and structuring. Additionally, I've tried to maintain a sequence of 1-2 sentences explanation followed by an example. The examples use the |
e6503b4
to
d0cc470
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Please take or leave my comments below.
lib/matplotlib/axes/_axes.py
Outdated
linewidth=2, markersize=12) | ||
|
||
When conflicting with *fmt*, these properties are taking precedence. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"...the kwarg properties take precedence"
lib/matplotlib/axes/_axes.py
Outdated
wonderful ways, including full names (``'green'``), hex | ||
strings (``'#008000'``), RGB or RGBA tuples (``(0,1,0,1)``) or | ||
grayscale intensities as a string (``'0.8'``). Of these, the | ||
string specifications can be used in place of a ``fmt`` group, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just say "In addition, colors can be specified using a Matplotlib matplotlib.colors
specification." If you want to add a few examples as well, thats fine, but a link to the colors module would help.
lib/matplotlib/axes/_axes.py
Outdated
optional format string. For example, each of the following is | ||
legal:: | ||
Plot lines and/or a series of markers. This is also known as line plot | ||
or XY (scatter) plot respectively. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need the use of "scatter" in here either. "Plot y versus x as lines and/or markers" is how I'd phrase this.
d0cc470
to
1cefa87
Compare
@timhoffm can you please email me? |
See Also | ||
-------- | ||
scatter : XY scatter plot with markers of variing size and/or color ( | ||
sometimes also called bubble chart). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sigh, I hate the term bubble chart :(
PR Summary
As part of #10148: Docstring update for
Axes.plot
.Note
This is quite a monster due to the different ways it can be used. I've moved the description of the format strings into the notes section at the bottom to declutter it a bit. It would even be better to move this description somewhere else in the docs and just reference it. There's other methods that would need the same information.