-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: Implement xlabel and ylabel options in Series.plot and DataFrame.plot #34223
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
Changes from 30 commits
7e461a1
1314059
8bcb313
24c3ede
dea38f2
cd9e7ac
e5e912b
045a76f
e69c080
bc7bad4
4ae4f17
0d32836
4d7216b
cc1b6d6
dbf8f1a
3fb1faa
f8ad37a
3f34099
4246f6e
408d08f
54824ab
8a24a40
6bb571a
66cf42f
7e2a7c9
31c8ccf
9d1d942
5335de8
2a8406d
8f12150
e1ade53
26bfa6e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -653,6 +653,16 @@ class PlotAccessor(PandasObject): | |||||
Set the x limits of the current axes. | ||||||
ylim : 2-tuple/list | ||||||
Set the y limits of the current axes. | ||||||
xlabel : label, default None | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We usually use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, thats fair! changed |
||||||
Name to use for the xlabel on x-axis. Default uses index name as xlabel. | ||||||
|
||||||
.. versionadded:: 1.1.0 | ||||||
|
||||||
ylabel : label, default None | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Name to use for the ylabel on y-axis. Default will show no ylabel. | ||||||
|
||||||
.. versionadded:: 1.1.0 | ||||||
|
||||||
rot : int, default None | ||||||
Rotation for ticks (xticks for vertical, yticks for horizontal | ||||||
plots). | ||||||
|
@@ -759,6 +769,8 @@ def _get_call_args(backend_name, data, args, kwargs): | |||||
("xerr", None), | ||||||
("label", None), | ||||||
("secondary_y", False), | ||||||
("xlabel", None), | ||||||
("ylabel", None), | ||||||
] | ||||||
elif isinstance(data, ABCDataFrame): | ||||||
arg_def = [ | ||||||
|
@@ -791,6 +803,8 @@ def _get_call_args(backend_name, data, args, kwargs): | |||||
("xerr", None), | ||||||
("secondary_y", False), | ||||||
("sort_columns", False), | ||||||
("xlabel", None), | ||||||
("ylabel", None), | ||||||
] | ||||||
else: | ||||||
raise TypeError( | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import re | ||
from typing import Optional | ||
from typing import List, Optional | ||
import warnings | ||
|
||
from matplotlib.artist import Artist | ||
import numpy as np | ||
|
||
from pandas._typing import Label | ||
from pandas.errors import AbstractMethodError | ||
from pandas.util._decorators import cache_readonly | ||
|
||
|
@@ -97,6 +99,8 @@ def __init__( | |
ylim=None, | ||
xticks=None, | ||
yticks=None, | ||
xlabel: Optional[Label] = None, | ||
ylabel: Optional[Label] = None, | ||
sort_columns=False, | ||
fontsize=None, | ||
secondary_y=False, | ||
|
@@ -138,6 +142,8 @@ def __init__( | |
self.ylim = ylim | ||
self.title = title | ||
self.use_index = use_index | ||
self.xlabel = xlabel | ||
self.ylabel = ylabel | ||
|
||
self.fontsize = fontsize | ||
|
||
|
@@ -155,8 +161,8 @@ def __init__( | |
|
||
self.grid = grid | ||
self.legend = legend | ||
self.legend_handles = [] | ||
self.legend_labels = [] | ||
self.legend_handles: List[Artist] = [] | ||
self.legend_labels: List[Label] = [] | ||
|
||
for attr in self._pop_attributes: | ||
value = kwds.pop(attr, self._attr_defaults.get(attr, None)) | ||
|
@@ -482,6 +488,11 @@ def _adorn_subplots(self): | |
if self.xlim is not None: | ||
ax.set_xlim(self.xlim) | ||
|
||
# GH9093, currently Pandas does not show ylabel, so if users provide | ||
# ylabel will set it as ylabel in the plot. | ||
if self.ylabel is not None: | ||
ax.set_ylabel(self.ylabel) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this consistent with May be I'm wrong, but feels like Would be probably good to add a test in the parametrization to make sure this works as expected. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good call! i think matplotlib's But i think it might be indeed nicer to be consistent with |
||
|
||
ax.grid(self.grid) | ||
|
||
if self.title: | ||
|
@@ -668,6 +679,10 @@ def _get_index_name(self): | |
if name is not None: | ||
name = pprint_thing(name) | ||
|
||
# GH 9093, override the default xlabel if xlabel is provided. | ||
if self.xlabel is not None: | ||
name = pprint_thing(self.xlabel) | ||
|
||
return name | ||
|
||
@classmethod | ||
|
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.
We use pandas in lowercase.
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.
changed!