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
Doc changes in add_subplot and add_axes #11459
Conversation
You ticked "Code is PEP 8 compliant" but it isn't. There are some line which are too long. I guess it would simplify review if you linked to the produced documentation. Where exactly is the SubplotBase documentation? |
a5f260c
to
a4a55cf
Compare
I don't know how to link to the produced documentation. The |
Drill down in the circleCI tests - it gives you a link to the documentation. Yes, we can do it, but if 6 reviewers have to click bunch of links, its nice to provide a shortcut. Also in this case, its not 100% clear what you think changed, and a link will be worth 1000 words. |
Thanks, I will try that but I cant do that before the tests are done. |
So here are links to the changed documenation: |
You still have a pep8 error! Lines need to be 79 characters long (no idea why 79 and not 80) |
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.
Lots of suggested changes here, but this seems very helpful overall. Thanks a lot!
lib/matplotlib/figure.py
Outdated
corner and increases to the right. | ||
|
||
A 3-digit integer, *pos*, can be used if all integers are less | ||
than 10. |
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.
pos is a three digit integer, where the first digit is the number of rows, the second the number of columns, and the third the index of the subplot. i.e. fig.add_subplot(235)
is the same as fig.add_subplot(2, 3, 5)
. Note that all integers must be less than 10 for this form to work.
'polar', rectilinear'}, optional | ||
The projection type of the axes. | ||
'polar', 'rectilinear', str}, optional | ||
The projection type of the `~.axes.Axes`. *str* is the name of |
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 projection type of the subplot (~.axes.Axes
).
(or introduce the fact that this method produces an Axes earlier. Otherwise the naive user is going to wonder what you are talking about...
lib/matplotlib/figure.py
Outdated
def add_subplot(self, *args, **kwargs): | ||
""" | ||
Add a subplot. | ||
Add a subplot to the figure. |
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.
Add an `~.axes.Axes` to the figure as part of a subplot arrangement.
lib/matplotlib/figure.py
Outdated
|
||
polar : boolean, optional | ||
If True, equivalent to projection='polar'. | ||
|
||
sharex, sharey : `~.axes.Axes`, optional | ||
Make the returned axes share the x or y `~matplotlib.axis` | ||
with the input axes. |
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.
Share the x or y ~matplotlib.axis
with sharex and/or sharey. The axis will have the same limits, ticks, and scale as the axis of the shared axes.
lib/matplotlib/figure.py
Outdated
|
||
Returns | ||
------- | ||
axes : Axes | ||
The axes of the subplot. | ||
axes : an `.axes.SubplotBase` subclass of `~.axes.Axes` (or a subclass \ |
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.
.axes.SubplotBase
didn't link. I think axes._subplots.SubplotBase
?
new axes), you must use a unique set of args and kwargs. The axes | ||
*label* attribute has been exposed for this purpose: if you want | ||
two axes that are otherwise identical to be added to the figure, | ||
make sure you give them unique labels. |
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.
What? Thats true for this method as well?
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.
Yes it is.
lib/matplotlib/pyplot.py
Outdated
rows and *ncols* columns. *index* starts at 1 in the upper left | ||
corner and increases to the right. | ||
|
||
A 3-digit integer, *pos*, can be used if all integers are less |
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.
As above...
lib/matplotlib/pyplot.py
Outdated
If *nrows*, *ncols* and *index* are all less than 10, they can also be | ||
given as a single, concatenated, three-digit number. | ||
sharex, sharey : `~.axes.Axes`, optional | ||
Make the returned axes share the x or y `~matplotlib.axis` |
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.
As above
rectilinear base class `~.axes.Axes` can be found in | ||
the following table but there might also be other keyword | ||
arguments if another projection is used. | ||
%(Axes)s |
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 didnt render... (I think you need the interp decorator)
plt.subplot(211) | ||
|
||
If you do not want this behavior, use the `.Figure.add_subplot` method | ||
or the `.pyplot.axes` function instead. |
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 just said these also have that behaviour....
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 confusing bit is that plt.subplot
will kill any other subplot that's below it, unless that subplot has been created with identical *args,**kwargs
.
Say you have a subplot
ax1 = plt.subplot(111)
Then
ax2 = plt.subplot(111, label="label")
will kill ax1
, while
ax2 = plt.subplot(111)
will activate ax1
(hence ax1 == ax2
)
lib/matplotlib/pyplot.py
Outdated
:file:`gallery/pie_and_polar_charts/polar_scatter.py` | ||
For an example | ||
# add a red subplot that share the x-axis with ax1 | ||
plt.subplot(224, sharex=ax1, facecolor='red') |
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.
a [..] subplot that shares the ...
lib/matplotlib/pyplot.py
Outdated
|
||
**Example:** | ||
#delete x2 from the figure |
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.
delete ax2
lib/matplotlib/pyplot.py
Outdated
|
||
.. plot:: gallery/subplots_axes_and_figures/subplot.py | ||
#add x2 to the figure again |
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.
add ax2
ffa0750
to
84869a7
Compare
I have finally made the suggested changes. |
@jklymak Because 80 char-wide emacs windows starts wrapping lines at 79 character. (That seems a good reason to be using vim 😇 ) |
lib/matplotlib/axes/_base.py
Outdated
`.Figure` coordinates. | ||
|
||
sharex, sharey : `~.axes.Axes`, optional | ||
The x or y `~.matlotlib.axis` is shared with the x or |
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.
There's a small typo on this line (matlotlib instead of matplotlib). I'm happy to fix this by pushing directly to your branch.
|
||
**kwargs | ||
Other optional keyword arguments: | ||
%(Axes)s |
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 recall that we had decided to move away from docstring interpolation a couple of years ago. I may be wrong, so ignore this (although it would be good to investigate and document this if it is the case).
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 know but I suggested to avoid those in another thread some weeks ago but it got turned down (and I have also kind of changed opinion).
def add_axes(self, *args, **kwargs): | ||
""" | ||
Add an axes to the figure. | ||
|
||
Call signature:: | ||
Call signatures:: |
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 can actually remove those call signatures. We don't use those anymore, as this information is contained in the numpydoc arguments list.
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 believe that those are sometimes still necessary when there are actually several more or less independent ways to call a function.
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.
Well… it's definitely a sign that the API for those particular functions are way to complicated, but there isn't much we can do about that these days.
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 agree. It would also be good to get rid of many of the (*args, **kwargs).
lib/matplotlib/figure.py
Outdated
The projection type of the axes. | ||
'polar', 'rectilinear', str}, optional | ||
The projection type of the `~.axes.Axes`. *str* is the name of | ||
a costum projection, see `~matplotlib.projections`. The default |
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.
Another small typo here (costum -> custom)
the following table but there might also be other keyword | ||
arguments if another projection is used, see the actual axes | ||
class. | ||
%(Axes)s |
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.
ditto about docstring interpolation.
lib/matplotlib/figure.py
Outdated
|
||
Notes | ||
----- | ||
If the figure already has a axes with key (*args*, |
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.
Small typo here as well (a -> an)
def add_subplot(self, *args, **kwargs): | ||
""" | ||
Add a subplot. | ||
Add an `~.axes.Axes` to the figure as part of a subplot arrangement. |
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.
👍
@fredrik-1 Thanks a lot for the contribution. I've got a couple of minor comments on the PR, but overall I find that it is an improvement to the documentation, so this is good to be merged, although I have to say I do not feel comfortable with using more docstring interpolation, as we are, to the best of my knowledge, trying to move away from this. |
84869a7
to
dbc4290
Compare
I have fixed the last typos. |
Thanks @fredrik-1 ! |
I did some changes in the documentation for
Figure.add_subplot
,Figure.add_axes
and their pyplot equivalents. Added some parameters (in the documentation) and tried to do them consistent to each other. I also did some small changes insubplots
, added anum
parameter and changed the example section to :: instead of >>>I also changed the docstring in
axes._base.__init__
and made it visible in the documentation.The links to the
SubplotBase
and some links in theaxes
kwargs list don't work but that would be fixed with my other PRs.