Skip to content

Commit df7f185

Browse files
committed
Added use_columns kwargs to parallel_plot to enable use of columns as xticks (allows for non-uniform scaling)
1 parent 626b115 commit df7f185

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

pandas/tools/plotting.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ def bootstrap_plot(series, fig=None, size=50, samples=500, **kwds):
412412

413413

414414
def parallel_coordinates(data, class_column, cols=None, ax=None, colors=None,
415-
**kwds):
415+
use_columns=False, **kwds):
416416
"""Parallel coordinates plotting.
417417
418418
Parameters:
@@ -422,6 +422,7 @@ def parallel_coordinates(data, class_column, cols=None, ax=None, colors=None,
422422
cols: A list of column names to use, optional
423423
ax: matplotlib axis object, optional
424424
colors: A list or tuple of colors to use for the different classes, optional
425+
use_columns: If true, columns will be used as xticks, optional
425426
kwds: A list of keywords for matplotlib plot method
426427
427428
Returns:
@@ -446,7 +447,12 @@ def random_color(column):
446447
used_legends = set([])
447448

448449
ncols = len(df.columns)
449-
x = range(ncols)
450+
451+
# Determine values to use for xticks
452+
if use_columns and np.all(np.isreal(list(df.columns))):
453+
x = df.columns
454+
else:
455+
x = range(ncols)
450456

451457
if ax == None:
452458
ax = plt.gca()
@@ -471,11 +477,12 @@ def random_color(column):
471477
else:
472478
ax.plot(x, y, color=colors[kls], **kwds)
473479

474-
for i in range(ncols):
480+
for i in x:
475481
ax.axvline(i, linewidth=1, color='black')
476482

477483
ax.set_xticks(x)
478484
ax.set_xticklabels(df.columns)
485+
ax.set_xlim(x[0], x[-1])
479486
ax.legend(loc='upper right')
480487
ax.grid()
481488
return ax

0 commit comments

Comments
 (0)