Skip to content

PERF: improve plotting performance by not stringifying all x data #18373

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions asv_bench/benchmarks/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,47 @@ def date_range(start=None, end=None, periods=None, freq=None):
from pandas.tools.plotting import andrews_curves


class Plotting(object):
goal_time = 0.2

def setup(self):
import matplotlib
matplotlib.use('Agg')
self.s = Series(np.random.randn(1000000))
self.df = DataFrame({'col': self.s})

def time_series_plot(self):
self.s.plot()

def time_frame_plot(self):
self.df.plot()


class TimeseriesPlotting(object):
goal_time = 0.2

def setup(self):
import matplotlib
matplotlib.use('Agg')
self.N = 2000
self.M = 5
self.df = DataFrame(np.random.randn(self.N, self.M), index=date_range('1/1/1975', periods=self.N))
N = 2000
M = 5
idx = date_range('1/1/1975', periods=N)
self.df = DataFrame(np.random.randn(N, M), index=idx)

idx_irregular = pd.DatetimeIndex(np.concatenate((idx.values[0:10],
idx.values[12:])))
self.df2 = DataFrame(np.random.randn(len(idx_irregular), M),
index=idx_irregular)

def time_plot_regular(self):
self.df.plot()

def time_plot_regular_compat(self):
self.df.plot(x_compat=True)

def time_plot_irregular(self):
self.df2.plot()


class Misc(object):
goal_time = 0.6
Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.21.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Deprecations
Performance Improvements
~~~~~~~~~~~~~~~~~~~~~~~~

-
- Improved performance of plotting large series/dataframes (:issue:`18236`).
-
-

Expand Down
12 changes: 8 additions & 4 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,16 @@ def _add_table(self):

def _post_plot_logic_common(self, ax, data):
"""Common post process for each axes"""
labels = [pprint_thing(key) for key in data.index]
labels = dict(zip(range(len(data.index)), labels))

def get_label(i):
try:
return pprint_thing(data.index[i])
except Exception:
return ''

if self.orientation == 'vertical' or self.orientation is None:
if self._need_to_set_index:
xticklabels = [labels.get(x, '') for x in ax.get_xticks()]
xticklabels = [get_label(x) for x in ax.get_xticks()]
ax.set_xticklabels(xticklabels)
self._apply_axis_properties(ax.xaxis, rot=self.rot,
fontsize=self.fontsize)
Expand All @@ -400,7 +404,7 @@ def _post_plot_logic_common(self, ax, data):

elif self.orientation == 'horizontal':
if self._need_to_set_index:
yticklabels = [labels.get(y, '') for y in ax.get_yticks()]
yticklabels = [get_label(y) for y in ax.get_yticks()]
ax.set_yticklabels(yticklabels)
self._apply_axis_properties(ax.yaxis, rot=self.rot,
fontsize=self.fontsize)
Expand Down