Skip to content

Commit 40d940b

Browse files
committed
Merge pull request #918 from danbirken/add_sort_columns
Add sort_columns parameter to plot to allow unsorted plots
2 parents be66c27 + 8ffdef9 commit 40d940b

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

pandas/core/frame.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3845,7 +3845,7 @@ def boxplot(self, column=None, by=None, ax=None, fontsize=None,
38453845

38463846
def plot(self, subplots=False, sharex=True, sharey=False, use_index=True,
38473847
figsize=None, grid=True, legend=True, rot=30, ax=None,
3848-
kind='line', **kwds):
3848+
kind='line', sort_columns=True, **kwds):
38493849
"""
38503850
Make line plot of DataFrame's series with the index on the x-axis using
38513851
matplotlib / pylab.
@@ -3861,6 +3861,8 @@ def plot(self, subplots=False, sharex=True, sharey=False, use_index=True,
38613861
use_index : boolean, default True
38623862
Use index as ticks for x axis
38633863
kind : {'line', 'bar'}
3864+
sort_columns: boolean, default True
3865+
Sort column names to determine plot ordering
38643866
kwds : keywords
38653867
Options to pass to Axis.plot
38663868
@@ -3903,7 +3905,12 @@ def plot(self, subplots=False, sharex=True, sharey=False, use_index=True,
39033905
need_to_set_xticklabels = False
39043906
x = range(len(self))
39053907

3906-
for i, col in enumerate(_try_sort(self.columns)):
3908+
if sort_columns:
3909+
columns = _try_sort(self.columns)
3910+
else:
3911+
columns = self.columns
3912+
3913+
for i, col in enumerate(columns):
39073914
empty = self[col].count() == 0
39083915
y = self[col].values if not empty else np.zeros(x.shape)
39093916

0 commit comments

Comments
 (0)