Visualization¶
We use the standard convention for referencing the matplotlib API:
In [1]: import matplotlib.pyplot as plt
The plots in this document are made using matplotlib’s ggplot
style (new in version 1.4):
import matplotlib
matplotlib.style.use('ggplot')
If your version of matplotlib is 1.3 or lower, you can set display.mpl_style
to 'default'
with pd.options.display.mpl_style = 'default'
to produce more appealing plots.
When set, matplotlib’s rcParams
are changed (globally!) to nicer-looking settings.
We provide the basics in pandas to easily create decent looking plots. See the ecosystem section for visualization libraries that go beyond the basics documented here.
Note
All calls to np.random
are seeded with 123456.
Basic Plotting: plot
¶
See the cookbook for some advanced strategies
The plot
method on Series and DataFrame is just a simple wrapper around
plt.plot()
:
In [2]: ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
In [3]: ts = ts.cumsum()
In [4]: ts.plot()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-4-132f3667ee95> in <module>()
----> 1 ts.plot()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
3495 colormap=colormap, table=table, yerr=yerr,
3496 xerr=xerr, label=label, secondary_y=secondary_y,
-> 3497 **kwds)
3498 __call__.__doc__ = plot_series.__doc__
3499
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
2585 yerr=yerr, xerr=xerr,
2586 label=label, secondary_y=secondary_y,
-> 2587 **kwds)
2588
2589
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

If the index consists of dates, it calls gcf().autofmt_xdate()
to try to format the x-axis nicely as per above.
On DataFrame, plot()
is a convenience to plot all of the columns with labels:
In [5]: df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index, columns=list('ABCD'))
In [6]: df = df.cumsum()
In [7]: plt.figure(); df.plot();

You can plot one column versus another using the x and y keywords in
plot()
:
In [8]: df3 = pd.DataFrame(np.random.randn(1000, 2), columns=['B', 'C']).cumsum()
In [9]: df3['A'] = pd.Series(list(range(len(df))))
In [10]: df3.plot(x='A', y='B')
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-10-055fbe5d7ac8> in <module>()
----> 1 df3.plot(x='A', y='B')
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
3669 fontsize=fontsize, colormap=colormap, table=table,
3670 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3671 sort_columns=sort_columns, **kwds)
3672 __call__.__doc__ = plot_frame.__doc__
3673
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2554 yerr=yerr, xerr=xerr,
2555 secondary_y=secondary_y, sort_columns=sort_columns,
-> 2556 **kwds)
2557
2558
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Note
For more formatting and styling options, see below.
Other Plots¶
Plotting methods allow for a handful of plot styles other than the
default Line plot. These methods can be provided as the kind
keyword argument to plot()
.
These include:
- ‘bar’ or ‘barh’ for bar plots
- ‘hist’ for histogram
- ‘box’ for boxplot
- ‘kde’ or
'density'
for density plots - ‘area’ for area plots
- ‘scatter’ for scatter plots
- ‘hexbin’ for hexagonal bin plots
- ‘pie’ for pie plots
New in version 0.17.
You can also create these other plots using the methods DataFrame.plot.<kind>
instead of providing the kind
keyword argument. This makes it easier to discover plot methods and the specific arguments they use:
In [11]: df = pd.DataFrame()
In [12]: df.plot.<TAB>
df.plot.area df.plot.barh df.plot.density df.plot.hist df.plot.line df.plot.scatter
df.plot.bar df.plot.box df.plot.hexbin df.plot.kde df.plot.pie
In addition to these kind
s, there are the DataFrame.hist(),
and DataFrame.boxplot() methods, which use a separate interface.
Finally, there are several plotting functions in pandas.tools.plotting
that take a Series
or DataFrame
as an argument. These
include
- Scatter Matrix
- Andrews Curves
- Parallel Coordinates
- Lag Plot
- Autocorrelation Plot
- Bootstrap Plot
- RadViz
Plots may also be adorned with errorbars or tables.
Bar plots¶
For labeled, non-time series data, you may wish to produce a bar plot:
In [13]: plt.figure();
In [14]: df.ix[5].plot(kind='bar'); plt.axhline(0, color='k')
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-14-3bc76e323eb4> in <module>()
----> 1 df.ix[5].plot(kind='bar'); plt.axhline(0, color='k')
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
3495 colormap=colormap, table=table, yerr=yerr,
3496 xerr=xerr, label=label, secondary_y=secondary_y,
-> 3497 **kwds)
3498 __call__.__doc__ = plot_series.__doc__
3499
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
2585 yerr=yerr, xerr=xerr,
2586 label=label, secondary_y=secondary_y,
-> 2587 **kwds)
2588
2589
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Calling a DataFrame’s plot()
method with kind='bar'
produces a multiple
bar plot:
In [15]: df2 = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd'])
In [16]: df2.plot(kind='bar');

To produce a stacked bar plot, pass stacked=True
:
In [17]: df2.plot(kind='bar', stacked=True);

To get horizontal bar plots, pass kind='barh'
:
In [18]: df2.plot(kind='barh', stacked=True);

Histograms¶
New in version 0.15.0.
Histogram can be drawn specifying kind='hist'
.
In [19]: df4 = pd.DataFrame({'a': np.random.randn(1000) + 1, 'b': np.random.randn(1000),
....: 'c': np.random.randn(1000) - 1}, columns=['a', 'b', 'c'])
....:
In [20]: plt.figure();
In [21]: df4.plot(kind='hist', alpha=0.5)
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-21-5007bea51681> in <module>()
----> 1 df4.plot(kind='hist', alpha=0.5)
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
3669 fontsize=fontsize, colormap=colormap, table=table,
3670 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3671 sort_columns=sort_columns, **kwds)
3672 __call__.__doc__ = plot_frame.__doc__
3673
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2554 yerr=yerr, xerr=xerr,
2555 secondary_y=secondary_y, sort_columns=sort_columns,
-> 2556 **kwds)
2557
2558
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Histogram can be stacked by stacked=True
. Bin size can be changed by bins
keyword.
In [22]: plt.figure();
In [23]: df4.plot(kind='hist', stacked=True, bins=20)
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-23-529c589b3632> in <module>()
----> 1 df4.plot(kind='hist', stacked=True, bins=20)
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
3669 fontsize=fontsize, colormap=colormap, table=table,
3670 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3671 sort_columns=sort_columns, **kwds)
3672 __call__.__doc__ = plot_frame.__doc__
3673
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2554 yerr=yerr, xerr=xerr,
2555 secondary_y=secondary_y, sort_columns=sort_columns,
-> 2556 **kwds)
2557
2558
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

You can pass other keywords supported by matplotlib hist
. For example, horizontal and cumulative histgram can be drawn by orientation='horizontal'
and cumulative='True'
.
In [24]: plt.figure();
In [25]: df4['a'].plot(kind='hist', orientation='horizontal', cumulative=True)
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-25-4f9a5a1b1b51> in <module>()
----> 1 df4['a'].plot(kind='hist', orientation='horizontal', cumulative=True)
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
3495 colormap=colormap, table=table, yerr=yerr,
3496 xerr=xerr, label=label, secondary_y=secondary_y,
-> 3497 **kwds)
3498 __call__.__doc__ = plot_series.__doc__
3499
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
2585 yerr=yerr, xerr=xerr,
2586 label=label, secondary_y=secondary_y,
-> 2587 **kwds)
2588
2589
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

See the hist
method and the
matplotlib hist documentation for more.
The existing interface DataFrame.hist
to plot histogram still can be used.
In [26]: plt.figure();
In [27]: df['A'].diff().hist()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-27-b7a456963eec> in <module>()
----> 1 df['A'].diff().hist()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in hist_series(self, by, ax, grid, xlabelsize, xrot, ylabelsize, yrot, figsize, bins, **kwds)
2889 # hack until the plotting interface is a bit more unified
2890 fig = kwds.pop('figure', plt.gcf() if plt.get_fignums() else
-> 2891 plt.figure(figsize=figsize))
2892 if (figsize is not None and tuple(figsize) !=
2893 tuple(fig.get_size_inches())):
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

DataFrame.hist()
plots the histograms of the columns on multiple
subplots:
In [28]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-28-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [29]: df.diff().hist(color='k', alpha=0.5, bins=50)
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-29-5a9111f991c3> in <module>()
----> 1 df.diff().hist(color='k', alpha=0.5, bins=50)
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in hist_frame(data, column, by, grid, xlabelsize, xrot, ylabelsize, yrot, ax, sharex, sharey, figsize, layout, bins, **kwds)
2832 fig, axes = _subplots(naxes=naxes, ax=ax, squeeze=False,
2833 sharex=sharex, sharey=sharey, figsize=figsize,
-> 2834 layout=layout)
2835 _axes = _flatten(axes)
2836
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _subplots(naxes, sharex, sharey, squeeze, subplot_kw, ax, layout, layout_type, **fig_kw)
3276
3277 if ax is None:
-> 3278 fig = plt.figure(**fig_kw)
3279 else:
3280 if com.is_list_like(ax):
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

New in version 0.10.0.
The by
keyword can be specified to plot grouped histograms:
In [30]: data = pd.Series(np.random.randn(1000))
In [31]: data.hist(by=np.random.randint(0, 4, 1000), figsize=(6, 4))
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-31-1bdd7ccb1dc8> in <module>()
----> 1 data.hist(by=np.random.randint(0, 4, 1000), figsize=(6, 4))
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in hist_series(self, by, ax, grid, xlabelsize, xrot, ylabelsize, yrot, figsize, bins, **kwds)
2913 axes = grouped_hist(self, by=by, ax=ax, grid=grid, figsize=figsize, bins=bins,
2914 xlabelsize=xlabelsize, xrot=xrot, ylabelsize=ylabelsize, yrot=yrot,
-> 2915 **kwds)
2916
2917 if hasattr(axes, 'ndim'):
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in grouped_hist(data, column, by, ax, bins, figsize, layout, sharex, sharey, rot, grid, xlabelsize, xrot, ylabelsize, yrot, **kwargs)
2954 fig, axes = _grouped_plot(plot_group, data, column=column,
2955 by=by, sharex=sharex, sharey=sharey, ax=ax,
-> 2956 figsize=figsize, layout=layout, rot=rot)
2957
2958 _set_ticks_props(axes, xlabelsize=xlabelsize, xrot=xrot,
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _grouped_plot(plotf, data, column, by, numeric_only, figsize, sharex, sharey, layout, rot, ax, **kwargs)
3057 fig, axes = _subplots(naxes=naxes, figsize=figsize,
3058 sharex=sharex, sharey=sharey, ax=ax,
-> 3059 layout=layout)
3060
3061 _axes = _flatten(axes)
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _subplots(naxes, sharex, sharey, squeeze, subplot_kw, ax, layout, layout_type, **fig_kw)
3276
3277 if ax is None:
-> 3278 fig = plt.figure(**fig_kw)
3279 else:
3280 if com.is_list_like(ax):
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Box Plots¶
Boxplot can be drawn calling a Series
and DataFrame.plot
with kind='box'
,
or DataFrame.boxplot
to visualize the distribution of values within each column.
New in version 0.15.0.
plot
method now supports kind='box'
to draw boxplot.
For instance, here is a boxplot representing five trials of 10 observations of a uniform random variable on [0,1).
In [32]: df = pd.DataFrame(np.random.rand(10, 5), columns=['A', 'B', 'C', 'D', 'E'])
In [33]: df.plot(kind='box')
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-33-06443674b77d> in <module>()
----> 1 df.plot(kind='box')
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
3669 fontsize=fontsize, colormap=colormap, table=table,
3670 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3671 sort_columns=sort_columns, **kwds)
3672 __call__.__doc__ = plot_frame.__doc__
3673
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2554 yerr=yerr, xerr=xerr,
2555 secondary_y=secondary_y, sort_columns=sort_columns,
-> 2556 **kwds)
2557
2558
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Boxplot can be colorized by passing color
keyword. You can pass a dict
whose keys are boxes
, whiskers
, medians
and caps
.
If some keys are missing in the dict
, default colors are used
for the corresponding artists. Also, boxplot has sym
keyword to specify fliers style.
When you pass other type of arguments via color
keyword, it will be directly
passed to matplotlib for all the boxes
, whiskers
, medians
and caps
colorization.
The colors are applied to every boxes to be drawn. If you want more complicated colorization, you can get each drawn artists by passing return_type.
In [34]: color = dict(boxes='DarkGreen', whiskers='DarkOrange',
....: medians='DarkBlue', caps='Gray')
....:
In [35]: df.plot(kind='box', color=color, sym='r+')
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-35-0e28a95e9e59> in <module>()
----> 1 df.plot(kind='box', color=color, sym='r+')
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
3669 fontsize=fontsize, colormap=colormap, table=table,
3670 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3671 sort_columns=sort_columns, **kwds)
3672 __call__.__doc__ = plot_frame.__doc__
3673
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2554 yerr=yerr, xerr=xerr,
2555 secondary_y=secondary_y, sort_columns=sort_columns,
-> 2556 **kwds)
2557
2558
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Also, you can pass other keywords supported by matplotlib boxplot
.
For example, horizontal and custom-positioned boxplot can be drawn by
vert=False
and positions
keywords.
In [36]: df.plot(kind='box', vert=False, positions=[1, 4, 5, 6, 8])
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-36-792a186918f3> in <module>()
----> 1 df.plot(kind='box', vert=False, positions=[1, 4, 5, 6, 8])
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
3669 fontsize=fontsize, colormap=colormap, table=table,
3670 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3671 sort_columns=sort_columns, **kwds)
3672 __call__.__doc__ = plot_frame.__doc__
3673
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2554 yerr=yerr, xerr=xerr,
2555 secondary_y=secondary_y, sort_columns=sort_columns,
-> 2556 **kwds)
2557
2558
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

See the boxplot
method and the
matplotlib boxplot documentation for more.
The existing interface DataFrame.boxplot
to plot boxplot still can be used.
In [37]: df = pd.DataFrame(np.random.rand(10,5))
In [38]: plt.figure();
In [39]: bp = df.boxplot()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-39-b1e3b3d5c3ca> in <module>()
----> 1 bp = df.boxplot()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/core/frame.pyc in boxplot(self, column, by, ax, fontsize, rot, grid, figsize, layout, return_type, **kwds)
5514 fontsize=fontsize, grid=grid, rot=rot,
5515 figsize=figsize, layout=layout, return_type=return_type,
-> 5516 **kwds)
5517 plt.draw_if_interactive()
5518 return ax
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in boxplot(data, column, by, ax, fontsize, rot, grid, figsize, layout, return_type, **kwds)
2702 return_type = 'dict'
2703 if ax is None:
-> 2704 ax = _gca()
2705 data = data._get_numeric_data()
2706 if columns is None:
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _gca()
404 def _gca():
405 import matplotlib.pyplot as plt
--> 406 return plt.gca()
407
408
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gca(**kwargs)
926 matplotlib.figure.Figure.gca : The figure's gca method.
927 """
--> 928 return gcf().gca(**kwargs)
929
930 # More ways of creating axes:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gcf()
576 return figManager.canvas.figure
577 else:
--> 578 return figure()
579
580
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

You can create a stratified boxplot using the by
keyword argument to create
groupings. For instance,
In [40]: df = pd.DataFrame(np.random.rand(10,2), columns=['Col1', 'Col2'] )
In [41]: df['X'] = pd.Series(['A','A','A','A','A','B','B','B','B','B'])
In [42]: plt.figure();
In [43]: bp = df.boxplot(by='X')
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-43-9a5b473d5a3e> in <module>()
----> 1 bp = df.boxplot(by='X')
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/core/frame.pyc in boxplot(self, column, by, ax, fontsize, rot, grid, figsize, layout, return_type, **kwds)
5514 fontsize=fontsize, grid=grid, rot=rot,
5515 figsize=figsize, layout=layout, return_type=return_type,
-> 5516 **kwds)
5517 plt.draw_if_interactive()
5518 return ax
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in boxplot(data, column, by, ax, fontsize, rot, grid, figsize, layout, return_type, **kwds)
2687 by=by, grid=grid, figsize=figsize,
2688 ax=ax, layout=layout,
-> 2689 return_type=return_type)
2690 else:
2691 if layout is not None:
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _grouped_plot_by_column(plotf, data, columns, by, numeric_only, grid, figsize, ax, layout, return_type, **kwargs)
3082 naxes = len(columns)
3083 fig, axes = _subplots(naxes=naxes, sharex=True, sharey=True,
-> 3084 figsize=figsize, ax=ax, layout=layout)
3085
3086 _axes = _flatten(axes)
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _subplots(naxes, sharex, sharey, squeeze, subplot_kw, ax, layout, layout_type, **fig_kw)
3276
3277 if ax is None:
-> 3278 fig = plt.figure(**fig_kw)
3279 else:
3280 if com.is_list_like(ax):
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

You can also pass a subset of columns to plot, as well as group by multiple columns:
In [44]: df = pd.DataFrame(np.random.rand(10,3), columns=['Col1', 'Col2', 'Col3'])
In [45]: df['X'] = pd.Series(['A','A','A','A','A','B','B','B','B','B'])
In [46]: df['Y'] = pd.Series(['A','B','A','B','A','B','A','B','A','B'])
In [47]: plt.figure();
In [48]: bp = df.boxplot(column=['Col1','Col2'], by=['X','Y'])
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-48-ccf0e8f85318> in <module>()
----> 1 bp = df.boxplot(column=['Col1','Col2'], by=['X','Y'])
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/core/frame.pyc in boxplot(self, column, by, ax, fontsize, rot, grid, figsize, layout, return_type, **kwds)
5514 fontsize=fontsize, grid=grid, rot=rot,
5515 figsize=figsize, layout=layout, return_type=return_type,
-> 5516 **kwds)
5517 plt.draw_if_interactive()
5518 return ax
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in boxplot(data, column, by, ax, fontsize, rot, grid, figsize, layout, return_type, **kwds)
2687 by=by, grid=grid, figsize=figsize,
2688 ax=ax, layout=layout,
-> 2689 return_type=return_type)
2690 else:
2691 if layout is not None:
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _grouped_plot_by_column(plotf, data, columns, by, numeric_only, grid, figsize, ax, layout, return_type, **kwargs)
3082 naxes = len(columns)
3083 fig, axes = _subplots(naxes=naxes, sharex=True, sharey=True,
-> 3084 figsize=figsize, ax=ax, layout=layout)
3085
3086 _axes = _flatten(axes)
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _subplots(naxes, sharex, sharey, squeeze, subplot_kw, ax, layout, layout_type, **fig_kw)
3276
3277 if ax is None:
-> 3278 fig = plt.figure(**fig_kw)
3279 else:
3280 if com.is_list_like(ax):
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Basically, plot functions return matplotlib Axes
as a return value.
In boxplot
, the return type can be changed by argument return_type
, and whether the subplots is enabled (subplots=True
in plot
or by
is specified in boxplot
).
When subplots=False
/ by
is None
:
- if
return_type
is'dict'
, a dictionary containing thematplotlib Lines
is returned. The keys are “boxes”, “caps”, “fliers”, “medians”, and “whiskers”. This is the default of
boxplot
in historical reason. Note thatplot(kind='box')
returnsAxes
as default as the same as other plots.
- if
if
return_type
is'axes'
, amatplotlib Axes
containing the boxplot is returned.- if
return_type
is'both'
a namedtuple containging thematplotlib Axes
and
matplotlib Lines
is returned
- if
When subplots=True
/ by
is some column of the DataFrame:
- A dict of
return_type
is returned, where the keys are the columns of the DataFrame. The plot has a facet for each column of the DataFrame, with a separate box for each value ofby
.
Finally, when calling boxplot on a Groupby
object, a dict of return_type
is returned, where the keys are the same as the Groupby object. The plot has a
facet for each key, with each facet containing a box for each column of the
DataFrame.
In [49]: np.random.seed(1234)
In [50]: df_box = pd.DataFrame(np.random.randn(50, 2))
In [51]: df_box['g'] = np.random.choice(['A', 'B'], size=50)
In [52]: df_box.loc[df_box['g'] == 'B', 1] += 3
In [53]: bp = df_box.boxplot(by='g')
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-53-2767ce298202> in <module>()
----> 1 bp = df_box.boxplot(by='g')
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/core/frame.pyc in boxplot(self, column, by, ax, fontsize, rot, grid, figsize, layout, return_type, **kwds)
5514 fontsize=fontsize, grid=grid, rot=rot,
5515 figsize=figsize, layout=layout, return_type=return_type,
-> 5516 **kwds)
5517 plt.draw_if_interactive()
5518 return ax
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in boxplot(data, column, by, ax, fontsize, rot, grid, figsize, layout, return_type, **kwds)
2687 by=by, grid=grid, figsize=figsize,
2688 ax=ax, layout=layout,
-> 2689 return_type=return_type)
2690 else:
2691 if layout is not None:
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _grouped_plot_by_column(plotf, data, columns, by, numeric_only, grid, figsize, ax, layout, return_type, **kwargs)
3082 naxes = len(columns)
3083 fig, axes = _subplots(naxes=naxes, sharex=True, sharey=True,
-> 3084 figsize=figsize, ax=ax, layout=layout)
3085
3086 _axes = _flatten(axes)
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _subplots(naxes, sharex, sharey, squeeze, subplot_kw, ax, layout, layout_type, **fig_kw)
3276
3277 if ax is None:
-> 3278 fig = plt.figure(**fig_kw)
3279 else:
3280 if com.is_list_like(ax):
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Compare to:
In [54]: bp = df_box.groupby('g').boxplot()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-54-e648d2cd2f8b> in <module>()
----> 1 bp = df_box.groupby('g').boxplot()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in boxplot_frame_groupby(grouped, subplots, column, fontsize, rot, grid, ax, figsize, layout, **kwds)
3014 fig, axes = _subplots(naxes=naxes, squeeze=False,
3015 ax=ax, sharex=False, sharey=True, figsize=figsize,
-> 3016 layout=layout)
3017 axes = _flatten(axes)
3018
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _subplots(naxes, sharex, sharey, squeeze, subplot_kw, ax, layout, layout_type, **fig_kw)
3276
3277 if ax is None:
-> 3278 fig = plt.figure(**fig_kw)
3279 else:
3280 if com.is_list_like(ax):
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Area Plot¶
New in version 0.14.
You can create area plots with Series.plot
and DataFrame.plot
by passing kind='area'
. Area plots are stacked by default. To produce stacked area plot, each column must be either all positive or all negative values.
When input data contains NaN, it will be automatically filled by 0. If you want to drop or fill by different values, use dataframe.dropna()
or dataframe.fillna()
before calling plot.
In [55]: df = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd'])
In [56]: df.plot(kind='area');

To produce an unstacked plot, pass stacked=False
. Alpha value is set to 0.5 unless otherwise specified:
In [57]: df.plot(kind='area', stacked=False);

Scatter Plot¶
New in version 0.13.
You can create scatter plots with DataFrame.plot
by passing kind='scatter'
.
Scatter plot requires numeric columns for x and y axis.
These can be specified by x
and y
keywords each.
In [58]: df = pd.DataFrame(np.random.rand(50, 4), columns=['a', 'b', 'c', 'd'])
In [59]: df.plot(kind='scatter', x='a', y='b');

To plot multiple column groups in a single axes, repeat plot
method specifying target ax
.
It is recommended to specify color
and label
keywords to distinguish each groups.
In [60]: ax = df.plot(kind='scatter', x='a', y='b',
....: color='DarkBlue', label='Group 1');
....:
In [61]: df.plot(kind='scatter', x='c', y='d',
....: color='DarkGreen', label='Group 2', ax=ax);
....:

The keyword c
may be given as the name of a column to provide colors for
each point:
In [62]: df.plot(kind='scatter', x='a', y='b', c='c', s=50);

You can pass other keywords supported by matplotlib scatter
.
Below example shows a bubble chart using a dataframe column values as bubble size.
In [63]: df.plot(kind='scatter', x='a', y='b', s=df['c']*200);

See the scatter
method and the
matplotlib scatter documentation for more.
Hexagonal Bin Plot¶
New in version 0.14.
You can create hexagonal bin plots with DataFrame.plot()
and
kind='hexbin'
.
Hexbin plots can be a useful alternative to scatter plots if your data are
too dense to plot each point individually.
In [64]: df = pd.DataFrame(np.random.randn(1000, 2), columns=['a', 'b'])
In [65]: df['b'] = df['b'] + np.arange(1000)
In [66]: df.plot(kind='hexbin', x='a', y='b', gridsize=25)
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-66-7779a862fb9d> in <module>()
----> 1 df.plot(kind='hexbin', x='a', y='b', gridsize=25)
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
3669 fontsize=fontsize, colormap=colormap, table=table,
3670 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3671 sort_columns=sort_columns, **kwds)
3672 __call__.__doc__ = plot_frame.__doc__
3673
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2554 yerr=yerr, xerr=xerr,
2555 secondary_y=secondary_y, sort_columns=sort_columns,
-> 2556 **kwds)
2557
2558
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

A useful keyword argument is gridsize
; it controls the number of hexagons
in the x-direction, and defaults to 100. A larger gridsize
means more, smaller
bins.
By default, a histogram of the counts around each (x, y)
point is computed.
You can specify alternative aggregations by passing values to the C
and
reduce_C_function
arguments. C
specifies the value at each (x, y)
point
and reduce_C_function
is a function of one argument that reduces all the
values in a bin to a single number (e.g. mean
, max
, sum
, std
). In this
example the positions are given by columns a
and b
, while the value is
given by column z
. The bins are aggregated with numpy’s max
function.
In [67]: df = pd.DataFrame(np.random.randn(1000, 2), columns=['a', 'b'])
In [68]: df['b'] = df['b'] = df['b'] + np.arange(1000)
In [69]: df['z'] = np.random.uniform(0, 3, 1000)
In [70]: df.plot(kind='hexbin', x='a', y='b', C='z', reduce_C_function=np.max,
....: gridsize=25)
....:
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-70-b29fcb79512f> in <module>()
1 df.plot(kind='hexbin', x='a', y='b', C='z', reduce_C_function=np.max,
----> 2 gridsize=25)
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
3669 fontsize=fontsize, colormap=colormap, table=table,
3670 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3671 sort_columns=sort_columns, **kwds)
3672 __call__.__doc__ = plot_frame.__doc__
3673
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2554 yerr=yerr, xerr=xerr,
2555 secondary_y=secondary_y, sort_columns=sort_columns,
-> 2556 **kwds)
2557
2558
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

See the hexbin
method and the
matplotlib hexbin documentation for more.
Pie plot¶
New in version 0.14.
You can create a pie plot with DataFrame.plot()
or Series.plot()
with kind='pie'
.
If your data includes any NaN
, they will be automatically filled with 0.
A ValueError
will be raised if there are any negative values in your data.
In [71]: series = pd.Series(3 * np.random.rand(4), index=['a', 'b', 'c', 'd'], name='series')
In [72]: series.plot(kind='pie', figsize=(6, 6))
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-72-accb31489e81> in <module>()
----> 1 series.plot(kind='pie', figsize=(6, 6))
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
3495 colormap=colormap, table=table, yerr=yerr,
3496 xerr=xerr, label=label, secondary_y=secondary_y,
-> 3497 **kwds)
3498 __call__.__doc__ = plot_series.__doc__
3499
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
2585 yerr=yerr, xerr=xerr,
2586 label=label, secondary_y=secondary_y,
-> 2587 **kwds)
2588
2589
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

For pie plots it’s best to use square figures, one’s with an equal aspect ratio. You can create the
figure with equal width and height, or force the aspect ratio to be equal after plotting by
calling ax.set_aspect('equal')
on the returned axes
object.
Note that pie plot with DataFrame
requires that you either specify a target column by the y
argument or subplots=True
. When y
is specified, pie plot of selected column
will be drawn. If subplots=True
is specified, pie plots for each column are drawn as subplots.
A legend will be drawn in each pie plots by default; specify legend=False
to hide it.
In [73]: df = pd.DataFrame(3 * np.random.rand(4, 2), index=['a', 'b', 'c', 'd'], columns=['x', 'y'])
In [74]: df.plot(kind='pie', subplots=True, figsize=(8, 4))
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-74-2746ec1fbfb5> in <module>()
----> 1 df.plot(kind='pie', subplots=True, figsize=(8, 4))
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
3669 fontsize=fontsize, colormap=colormap, table=table,
3670 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3671 sort_columns=sort_columns, **kwds)
3672 __call__.__doc__ = plot_frame.__doc__
3673
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2554 yerr=yerr, xerr=xerr,
2555 secondary_y=secondary_y, sort_columns=sort_columns,
-> 2556 **kwds)
2557
2558
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1032 figsize=self.figsize, ax=self.ax,
1033 layout=self.layout,
-> 1034 layout_type=self._layout_type)
1035 else:
1036 if self.ax is None:
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _subplots(naxes, sharex, sharey, squeeze, subplot_kw, ax, layout, layout_type, **fig_kw)
3276
3277 if ax is None:
-> 3278 fig = plt.figure(**fig_kw)
3279 else:
3280 if com.is_list_like(ax):
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

You can use the labels
and colors
keywords to specify the labels and colors of each wedge.
Warning
Most pandas plots use the the label
and color
arguments (note the lack of “s” on those).
To be consistent with matplotlib.pyplot.pie()
you must use labels
and colors
.
If you want to hide wedge labels, specify labels=None
.
If fontsize
is specified, the value will be applied to wedge labels.
Also, other keywords supported by matplotlib.pyplot.pie()
can be used.
In [75]: series.plot(kind='pie', labels=['AA', 'BB', 'CC', 'DD'], colors=['r', 'g', 'b', 'c'],
....: autopct='%.2f', fontsize=20, figsize=(6, 6))
....:
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-75-cb8dc5135066> in <module>()
1 series.plot(kind='pie', labels=['AA', 'BB', 'CC', 'DD'], colors=['r', 'g', 'b', 'c'],
----> 2 autopct='%.2f', fontsize=20, figsize=(6, 6))
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
3495 colormap=colormap, table=table, yerr=yerr,
3496 xerr=xerr, label=label, secondary_y=secondary_y,
-> 3497 **kwds)
3498 __call__.__doc__ = plot_series.__doc__
3499
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
2585 yerr=yerr, xerr=xerr,
2586 label=label, secondary_y=secondary_y,
-> 2587 **kwds)
2588
2589
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

If you pass values whose sum total is less than 1.0, matplotlib draws a semicircle.
In [76]: series = pd.Series([0.1] * 4, index=['a', 'b', 'c', 'd'], name='series2')
In [77]: series.plot(kind='pie', figsize=(6, 6))
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-77-accb31489e81> in <module>()
----> 1 series.plot(kind='pie', figsize=(6, 6))
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
3495 colormap=colormap, table=table, yerr=yerr,
3496 xerr=xerr, label=label, secondary_y=secondary_y,
-> 3497 **kwds)
3498 __call__.__doc__ = plot_series.__doc__
3499
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
2585 yerr=yerr, xerr=xerr,
2586 label=label, secondary_y=secondary_y,
-> 2587 **kwds)
2588
2589
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

See the matplotlib pie documentation for more.
Plotting with Missing Data¶
Pandas tries to be pragmatic about plotting DataFrames or Series that contain missing data. Missing values are dropped, left out, or filled depending on the plot type.
Plot Type | NaN Handling |
---|---|
Line | Leave gaps at NaNs |
Line (stacked) | Fill 0’s |
Bar | Fill 0’s |
Scatter | Drop NaNs |
Histogram | Drop NaNs (column-wise) |
Box | Drop NaNs (column-wise) |
Area | Fill 0’s |
KDE | Drop NaNs (column-wise) |
Hexbin | Drop NaNs |
Pie | Fill 0’s |
If any of these defaults are not what you want, or if you want to be
explicit about how missing values are handled, consider using
fillna()
or dropna()
before plotting.
Plotting Tools¶
These functions can be imported from pandas.tools.plotting
and take a Series
or DataFrame
as an argument.
Scatter Matrix Plot¶
New in version 0.7.3.
You can create a scatter plot matrix using the
scatter_matrix
method in pandas.tools.plotting
:
In [78]: from pandas.tools.plotting import scatter_matrix
In [79]: df = pd.DataFrame(np.random.randn(1000, 4), columns=['a', 'b', 'c', 'd'])
In [80]: scatter_matrix(df, alpha=0.2, figsize=(6, 6), diagonal='kde')
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-80-5cffe88eb027> in <module>()
----> 1 scatter_matrix(df, alpha=0.2, figsize=(6, 6), diagonal='kde')
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in scatter_matrix(frame, alpha, figsize, ax, grid, diagonal, marker, density_kwds, hist_kwds, range_padding, **kwds)
323 naxes = n * n
324 fig, axes = _subplots(naxes=naxes, figsize=figsize, ax=ax,
--> 325 squeeze=False)
326
327 # no gaps between subplots
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _subplots(naxes, sharex, sharey, squeeze, subplot_kw, ax, layout, layout_type, **fig_kw)
3276
3277 if ax is None:
-> 3278 fig = plt.figure(**fig_kw)
3279 else:
3280 if com.is_list_like(ax):
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Density Plot¶
New in version 0.8.0.
You can create density plots using the Series/DataFrame.plot and
setting kind='kde'
:
In [81]: ser = pd.Series(np.random.randn(1000))
In [82]: ser.plot(kind='kde')
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-82-ae1c951bf9d1> in <module>()
----> 1 ser.plot(kind='kde')
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
3495 colormap=colormap, table=table, yerr=yerr,
3496 xerr=xerr, label=label, secondary_y=secondary_y,
-> 3497 **kwds)
3498 __call__.__doc__ = plot_series.__doc__
3499
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
2585 yerr=yerr, xerr=xerr,
2586 label=label, secondary_y=secondary_y,
-> 2587 **kwds)
2588
2589
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Andrews Curves¶
Andrews curves allow one to plot multivariate data as a large number of curves that are created using the attributes of samples as coefficients for Fourier series. By coloring these curves differently for each class it is possible to visualize data clustering. Curves belonging to samples of the same class will usually be closer together and form larger structures.
Note: The “Iris” dataset is available here.
In [83]: from pandas.tools.plotting import andrews_curves
In [84]: data = pd.read_csv('data/iris.data')
In [85]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-85-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [86]: andrews_curves(data, 'Name')
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-86-0f95ea8c8c98> in <module>()
----> 1 andrews_curves(data, 'Name')
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/util/decorators.pyc in wrapper(*args, **kwargs)
87 else:
88 kwargs[new_arg_name] = new_arg_value
---> 89 return func(*args, **kwargs)
90 return wrapper
91 return _deprecate_kwarg
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in andrews_curves(frame, class_column, ax, samples, color, colormap, **kwds)
557 colors = dict(zip(classes, color_values))
558 if ax is None:
--> 559 ax = plt.gca(xlim=(-pi, pi))
560 for i in range(n):
561 row = df.iloc[i].values
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gca(**kwargs)
926 matplotlib.figure.Figure.gca : The figure's gca method.
927 """
--> 928 return gcf().gca(**kwargs)
929
930 # More ways of creating axes:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gcf()
576 return figManager.canvas.figure
577 else:
--> 578 return figure()
579
580
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Parallel Coordinates¶
Parallel coordinates is a plotting technique for plotting multivariate data. It allows one to see clusters in data and to estimate other statistics visually. Using parallel coordinates points are represented as connected line segments. Each vertical line represents one attribute. One set of connected line segments represents one data point. Points that tend to cluster will appear closer together.
In [87]: from pandas.tools.plotting import parallel_coordinates
In [88]: data = pd.read_csv('data/iris.data')
In [89]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-89-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [90]: parallel_coordinates(data, 'Name')
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-90-be6a93ae858a> in <module>()
----> 1 parallel_coordinates(data, 'Name')
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/util/decorators.pyc in wrapper(*args, **kwargs)
87 else:
88 kwargs[new_arg_name] = new_arg_value
---> 89 return func(*args, **kwargs)
90 return wrapper
91 return _deprecate_kwarg
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/util/decorators.pyc in wrapper(*args, **kwargs)
87 else:
88 kwargs[new_arg_name] = new_arg_value
---> 89 return func(*args, **kwargs)
90 return wrapper
91 return _deprecate_kwarg
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in parallel_coordinates(frame, class_column, cols, ax, color, use_columns, xticks, colormap, axvlines, axvlines_kwds, **kwds)
709
710 if ax is None:
--> 711 ax = plt.gca()
712
713 color_values = _get_standard_colors(num_colors=len(classes),
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gca(**kwargs)
926 matplotlib.figure.Figure.gca : The figure's gca method.
927 """
--> 928 return gcf().gca(**kwargs)
929
930 # More ways of creating axes:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gcf()
576 return figManager.canvas.figure
577 else:
--> 578 return figure()
579
580
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Lag Plot¶
Lag plots are used to check if a data set or time series is random. Random data should not exhibit any structure in the lag plot. Non-random structure implies that the underlying data are not random.
In [91]: from pandas.tools.plotting import lag_plot
In [92]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-92-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [93]: data = pd.Series(0.1 * np.random.rand(1000) +
....: 0.9 * np.sin(np.linspace(-99 * np.pi, 99 * np.pi, num=1000)))
....:
In [94]: lag_plot(data)
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-94-f8d9d4e4ce9e> in <module>()
----> 1 lag_plot(data)
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in lag_plot(series, lag, ax, **kwds)
762 y2 = data[lag:]
763 if ax is None:
--> 764 ax = plt.gca()
765 ax.set_xlabel("y(t)")
766 ax.set_ylabel("y(t + %s)" % lag)
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gca(**kwargs)
926 matplotlib.figure.Figure.gca : The figure's gca method.
927 """
--> 928 return gcf().gca(**kwargs)
929
930 # More ways of creating axes:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gcf()
576 return figManager.canvas.figure
577 else:
--> 578 return figure()
579
580
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Autocorrelation Plot¶
Autocorrelation plots are often used for checking randomness in time series. This is done by computing autocorrelations for data values at varying time lags. If time series is random, such autocorrelations should be near zero for any and all time-lag separations. If time series is non-random then one or more of the autocorrelations will be significantly non-zero. The horizontal lines displayed in the plot correspond to 95% and 99% confidence bands. The dashed line is 99% confidence band.
In [95]: from pandas.tools.plotting import autocorrelation_plot
In [96]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-96-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [97]: data = pd.Series(0.7 * np.random.rand(1000) +
....: 0.3 * np.sin(np.linspace(-9 * np.pi, 9 * np.pi, num=1000)))
....:
In [98]: autocorrelation_plot(data)
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-98-d14de8189d5a> in <module>()
----> 1 autocorrelation_plot(data)
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in autocorrelation_plot(series, ax, **kwds)
787 data = np.asarray(series)
788 if ax is None:
--> 789 ax = plt.gca(xlim=(1, n), ylim=(-1.0, 1.0))
790 mean = np.mean(data)
791 c0 = np.sum((data - mean) ** 2) / float(n)
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gca(**kwargs)
926 matplotlib.figure.Figure.gca : The figure's gca method.
927 """
--> 928 return gcf().gca(**kwargs)
929
930 # More ways of creating axes:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gcf()
576 return figManager.canvas.figure
577 else:
--> 578 return figure()
579
580
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Bootstrap Plot¶
Bootstrap plots are used to visually assess the uncertainty of a statistic, such as mean, median, midrange, etc. A random subset of a specified size is selected from a data set, the statistic in question is computed for this subset and the process is repeated a specified number of times. Resulting plots and histograms are what constitutes the bootstrap plot.
In [99]: from pandas.tools.plotting import bootstrap_plot
In [100]: data = pd.Series(np.random.rand(1000))
In [101]: bootstrap_plot(data, size=50, samples=500, color='grey')
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-101-ab35f51c8c35> in <module>()
----> 1 bootstrap_plot(data, size=50, samples=500, color='grey')
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in bootstrap_plot(series, fig, size, samples, **kwds)
603 for sampling in samplings])
604 if fig is None:
--> 605 fig = plt.figure()
606 x = lrange(samples)
607 axes = []
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

RadViz¶
RadViz is a way of visualizing multi-variate data. It is based on a simple spring tension minimization algorithm. Basically you set up a bunch of points in a plane. In our case they are equally spaced on a unit circle. Each point represents a single attribute. You then pretend that each sample in the data set is attached to each of these points by a spring, the stiffness of which is proportional to the numerical value of that attribute (they are normalized to unit interval). The point in the plane, where our sample settles to (where the forces acting on our sample are at an equilibrium) is where a dot representing our sample will be drawn. Depending on which class that sample belongs it will be colored differently.
Note: The “Iris” dataset is available here.
In [102]: from pandas.tools.plotting import radviz
In [103]: data = pd.read_csv('data/iris.data')
In [104]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-104-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [105]: radviz(data, 'Name')
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-105-338b038cf6ed> in <module>()
----> 1 radviz(data, 'Name')
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in radviz(frame, class_column, ax, color, colormap, **kwds)
455
456 if ax is None:
--> 457 ax = plt.gca(xlim=[-1, 1], ylim=[-1, 1])
458
459 to_plot = {}
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gca(**kwargs)
926 matplotlib.figure.Figure.gca : The figure's gca method.
927 """
--> 928 return gcf().gca(**kwargs)
929
930 # More ways of creating axes:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gcf()
576 return figManager.canvas.figure
577 else:
--> 578 return figure()
579
580
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Plot Formatting¶
Most plotting methods have a set of keyword arguments that control the layout and formatting of the returned plot:
In [106]: plt.figure(); ts.plot(style='k--', label='Series');

For each kind of plot (e.g. line, bar, scatter) any additional arguments
keywords are passed along to the corresponding matplotlib function
(ax.plot()
,
ax.bar()
,
ax.scatter()
). These can be used
to control additional styling, beyond what pandas provides.
Controlling the Legend¶
You may set the legend
argument to False
to hide the legend, which is
shown by default.
In [107]: df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index, columns=list('ABCD'))
In [108]: df = df.cumsum()
In [109]: df.plot(legend=False)
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-109-77cce09d96e9> in <module>()
----> 1 df.plot(legend=False)
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
3669 fontsize=fontsize, colormap=colormap, table=table,
3670 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3671 sort_columns=sort_columns, **kwds)
3672 __call__.__doc__ = plot_frame.__doc__
3673
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2554 yerr=yerr, xerr=xerr,
2555 secondary_y=secondary_y, sort_columns=sort_columns,
-> 2556 **kwds)
2557
2558
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Scales¶
You may pass logy
to get a log-scale Y axis.
In [110]: ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
In [111]: ts = np.exp(ts.cumsum())
In [112]: ts.plot(logy=True)
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-112-5ab34878158b> in <module>()
----> 1 ts.plot(logy=True)
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
3495 colormap=colormap, table=table, yerr=yerr,
3496 xerr=xerr, label=label, secondary_y=secondary_y,
-> 3497 **kwds)
3498 __call__.__doc__ = plot_series.__doc__
3499
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
2585 yerr=yerr, xerr=xerr,
2586 label=label, secondary_y=secondary_y,
-> 2587 **kwds)
2588
2589
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

See also the logx
and loglog
keyword arguments.
Plotting on a Secondary Y-axis¶
To plot data on a secondary y-axis, use the secondary_y
keyword:
In [113]: df.A.plot()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-113-0bd2f2663ad1> in <module>()
----> 1 df.A.plot()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
3495 colormap=colormap, table=table, yerr=yerr,
3496 xerr=xerr, label=label, secondary_y=secondary_y,
-> 3497 **kwds)
3498 __call__.__doc__ = plot_series.__doc__
3499
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
2585 yerr=yerr, xerr=xerr,
2586 label=label, secondary_y=secondary_y,
-> 2587 **kwds)
2588
2589
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [114]: df.B.plot(secondary_y=True, style='g')
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-114-30575e3a7dff> in <module>()
----> 1 df.B.plot(secondary_y=True, style='g')
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
3495 colormap=colormap, table=table, yerr=yerr,
3496 xerr=xerr, label=label, secondary_y=secondary_y,
-> 3497 **kwds)
3498 __call__.__doc__ = plot_series.__doc__
3499
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
2585 yerr=yerr, xerr=xerr,
2586 label=label, secondary_y=secondary_y,
-> 2587 **kwds)
2588
2589
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

To plot some columns in a DataFrame, give the column names to the secondary_y
keyword:
In [115]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-115-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [116]: ax = df.plot(secondary_y=['A', 'B'])
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-116-e67c19206c33> in <module>()
----> 1 ax = df.plot(secondary_y=['A', 'B'])
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
3669 fontsize=fontsize, colormap=colormap, table=table,
3670 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3671 sort_columns=sort_columns, **kwds)
3672 __call__.__doc__ = plot_frame.__doc__
3673
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2554 yerr=yerr, xerr=xerr,
2555 secondary_y=secondary_y, sort_columns=sort_columns,
-> 2556 **kwds)
2557
2558
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [117]: ax.set_ylabel('CD scale')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-117-7f89d3ebe2a5> in <module>()
----> 1 ax.set_ylabel('CD scale')
AttributeError: 'str' object has no attribute 'set_ylabel'
In [118]: ax.right_ax.set_ylabel('AB scale')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-118-e1154c6f5d29> in <module>()
----> 1 ax.right_ax.set_ylabel('AB scale')
AttributeError: 'str' object has no attribute 'right_ax'

Note that the columns plotted on the secondary y-axis is automatically marked
with “(right)” in the legend. To turn off the automatic marking, use the
mark_right=False
keyword:
In [119]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-119-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [120]: df.plot(secondary_y=['A', 'B'], mark_right=False)
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-120-90863fcd860d> in <module>()
----> 1 df.plot(secondary_y=['A', 'B'], mark_right=False)
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
3669 fontsize=fontsize, colormap=colormap, table=table,
3670 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3671 sort_columns=sort_columns, **kwds)
3672 __call__.__doc__ = plot_frame.__doc__
3673
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2554 yerr=yerr, xerr=xerr,
2555 secondary_y=secondary_y, sort_columns=sort_columns,
-> 2556 **kwds)
2557
2558
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Suppressing Tick Resolution Adjustment¶
pandas includes automatic tick resolution adjustment for regular frequency
time-series data. For limited cases where pandas cannot infer the frequency
information (e.g., in an externally created twinx
), you can choose to
suppress this behavior for alignment purposes.
Here is the default behavior, notice how the x-axis tick labelling is performed:
In [121]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-121-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [122]: df.A.plot()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-122-0bd2f2663ad1> in <module>()
----> 1 df.A.plot()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
3495 colormap=colormap, table=table, yerr=yerr,
3496 xerr=xerr, label=label, secondary_y=secondary_y,
-> 3497 **kwds)
3498 __call__.__doc__ = plot_series.__doc__
3499
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
2585 yerr=yerr, xerr=xerr,
2586 label=label, secondary_y=secondary_y,
-> 2587 **kwds)
2588
2589
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Using the x_compat
parameter, you can suppress this behavior:
In [123]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-123-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [124]: df.A.plot(x_compat=True)
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-124-948658db877b> in <module>()
----> 1 df.A.plot(x_compat=True)
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
3495 colormap=colormap, table=table, yerr=yerr,
3496 xerr=xerr, label=label, secondary_y=secondary_y,
-> 3497 **kwds)
3498 __call__.__doc__ = plot_series.__doc__
3499
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
2585 yerr=yerr, xerr=xerr,
2586 label=label, secondary_y=secondary_y,
-> 2587 **kwds)
2588
2589
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

If you have more than one plot that needs to be suppressed, the use
method
in pandas.plot_params
can be used in a with statement:
In [125]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-125-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [126]: with pd.plot_params.use('x_compat', True):
.....: df.A.plot(color='r')
.....: df.B.plot(color='g')
.....: df.C.plot(color='b')
.....:
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-126-e8c65923f3cd> in <module>()
1 with pd.plot_params.use('x_compat', True):
----> 2 df.A.plot(color='r')
3 df.B.plot(color='g')
4 df.C.plot(color='b')
5
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
3495 colormap=colormap, table=table, yerr=yerr,
3496 xerr=xerr, label=label, secondary_y=secondary_y,
-> 3497 **kwds)
3498 __call__.__doc__ = plot_series.__doc__
3499
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
2585 yerr=yerr, xerr=xerr,
2586 label=label, secondary_y=secondary_y,
-> 2587 **kwds)
2588
2589
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Subplots¶
Each Series in a DataFrame can be plotted on a different axis
with the subplots
keyword:
In [127]: df.plot(subplots=True, figsize=(6, 6));

Using Layout and Targeting Multiple Axes¶
The layout of subplots can be specified by layout
keyword. It can accept
(rows, columns)
. The layout
keyword can be used in
hist
and boxplot
also. If input is invalid, ValueError
will be raised.
The number of axes which can be contained by rows x columns specified by layout
must be
larger than the number of required subplots. If layout can contain more axes than required,
blank axes are not drawn. Similar to a numpy array’s reshape
method, you
can use -1
for one dimension to automatically calculate the number of rows
or columns needed, given the other.
In [128]: df.plot(subplots=True, layout=(2, 3), figsize=(6, 6), sharex=False);

The above example is identical to using
In [129]: df.plot(subplots=True, layout=(2, -1), figsize=(6, 6), sharex=False);
The required number of columns (3) is inferred from the number of series to plot and the given number of rows (2).
Also, you can pass multiple axes created beforehand as list-like via ax
keyword.
This allows to use more complicated layout.
The passed axes must be the same number as the subplots being drawn.
When multiple axes are passed via ax
keyword, layout
, sharex
and sharey
keywords
don’t affect to the output. You should explicitly pass sharex=False
and sharey=False
,
otherwise you will see a warning.
In [130]: fig, axes = plt.subplots(4, 4, figsize=(6, 6));
In [131]: plt.subplots_adjust(wspace=0.5, hspace=0.5);
In [132]: target1 = [axes[0][0], axes[1][1], axes[2][2], axes[3][3]]
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-132-bce2ff74b6af> in <module>()
----> 1 target1 = [axes[0][0], axes[1][1], axes[2][2], axes[3][3]]
NameError: name 'axes' is not defined
In [133]: target2 = [axes[3][0], axes[2][1], axes[1][2], axes[0][3]]
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-133-0efbdf9a4435> in <module>()
----> 1 target2 = [axes[3][0], axes[2][1], axes[1][2], axes[0][3]]
NameError: name 'axes' is not defined
In [134]: df.plot(subplots=True, ax=target1, legend=False, sharex=False, sharey=False);
In [135]: (-df).plot(subplots=True, ax=target2, legend=False, sharex=False, sharey=False);

Another option is passing an ax
argument to Series.plot()
to plot on a particular axis:
In [136]: fig, axes = plt.subplots(nrows=2, ncols=2)
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-136-2353b2a37614> in <module>()
----> 1 fig, axes = plt.subplots(nrows=2, ncols=2)
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in subplots(nrows, ncols, sharex, sharey, squeeze, subplot_kw, gridspec_kw, **fig_kw)
1175 gridspec_kw = {}
1176
-> 1177 fig = figure(**fig_kw)
1178 gs = GridSpec(nrows, ncols, **gridspec_kw)
1179
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [137]: df['A'].plot(ax=axes[0,0]); axes[0,0].set_title('A');
In [138]: df['B'].plot(ax=axes[0,1]); axes[0,1].set_title('B');
In [139]: df['C'].plot(ax=axes[1,0]); axes[1,0].set_title('C');
In [140]: df['D'].plot(ax=axes[1,1]); axes[1,1].set_title('D');

Plotting With Error Bars¶
New in version 0.14.
Plotting with error bars is now supported in the DataFrame.plot()
and Series.plot()
Horizontal and vertical errorbars can be supplied to the xerr
and yerr
keyword arguments to plot()
. The error values can be specified using a variety of formats.
- As a
DataFrame
ordict
of errors with column names matching thecolumns
attribute of the plottingDataFrame
or matching thename
attribute of theSeries
- As a
str
indicating which of the columns of plottingDataFrame
contain the error values - As raw values (
list
,tuple
, ornp.ndarray
). Must be the same length as the plottingDataFrame
/Series
Asymmetrical error bars are also supported, however raw error values must be provided in this case. For a M
length Series
, a Mx2
array should be provided indicating lower and upper (or left and right) errors. For a MxN
DataFrame
, asymmetrical errors should be in a Mx2xN
array.
Here is an example of one way to easily plot group means with standard deviations from the raw data.
# Generate the data
In [141]: ix3 = pd.MultiIndex.from_arrays([['a', 'a', 'a', 'a', 'b', 'b', 'b', 'b'], ['foo', 'foo', 'bar', 'bar', 'foo', 'foo', 'bar', 'bar']], names=['letter', 'word'])
In [142]: df3 = pd.DataFrame({'data1': [3, 2, 4, 3, 2, 4, 3, 2], 'data2': [6, 5, 7, 5, 4, 5, 6, 5]}, index=ix3)
# Group by index labels and take the means and standard deviations for each group
In [143]: gp3 = df3.groupby(level=('letter', 'word'))
In [144]: means = gp3.mean()
In [145]: errors = gp3.std()
In [146]: means
Out[146]:
data1 data2
letter word
a bar 3.5 6.0
foo 2.5 5.5
b bar 2.5 5.5
foo 3.0 4.5
In [147]: errors
Out[147]:
data1 data2
letter word
a bar 0.707107 1.414214
foo 0.707107 0.707107
b bar 0.707107 0.707107
foo 1.414214 0.707107
# Plot
In [148]: fig, ax = plt.subplots()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-148-c49ba9de65d3> in <module>()
----> 1 fig, ax = plt.subplots()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in subplots(nrows, ncols, sharex, sharey, squeeze, subplot_kw, gridspec_kw, **fig_kw)
1175 gridspec_kw = {}
1176
-> 1177 fig = figure(**fig_kw)
1178 gs = GridSpec(nrows, ncols, **gridspec_kw)
1179
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [149]: means.plot(yerr=errors, ax=ax, kind='bar')
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-149-65bc565fe811> in <module>()
----> 1 means.plot(yerr=errors, ax=ax, kind='bar')
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
3669 fontsize=fontsize, colormap=colormap, table=table,
3670 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3671 sort_columns=sort_columns, **kwds)
3672 __call__.__doc__ = plot_frame.__doc__
3673
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2554 yerr=yerr, xerr=xerr,
2555 secondary_y=secondary_y, sort_columns=sort_columns,
-> 2556 **kwds)
2557
2558
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1038 axes = fig.add_subplot(111)
1039 else:
-> 1040 fig = self.ax.get_figure()
1041 if self.figsize is not None:
1042 fig.set_size_inches(self.figsize)
AttributeError: 'str' object has no attribute 'get_figure'

Plotting Tables¶
New in version 0.14.
Plotting with matplotlib table is now supported in DataFrame.plot()
and Series.plot()
with a table
keyword. The table
keyword can accept bool
, DataFrame
or Series
. The simple way to draw a table is to specify table=True
. Data will be transposed to meet matplotlib’s default layout.
In [150]: fig, ax = plt.subplots(1, 1)
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-150-f6bb38fc9afd> in <module>()
----> 1 fig, ax = plt.subplots(1, 1)
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in subplots(nrows, ncols, sharex, sharey, squeeze, subplot_kw, gridspec_kw, **fig_kw)
1175 gridspec_kw = {}
1176
-> 1177 fig = figure(**fig_kw)
1178 gs = GridSpec(nrows, ncols, **gridspec_kw)
1179
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [151]: df = pd.DataFrame(np.random.rand(5, 3), columns=['a', 'b', 'c'])
In [152]: ax.get_xaxis().set_visible(False) # Hide Ticks
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-152-fa7059ff28d8> in <module>()
----> 1 ax.get_xaxis().set_visible(False) # Hide Ticks
AttributeError: 'str' object has no attribute 'get_xaxis'
In [153]: df.plot(table=True, ax=ax)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-153-42849ed7bc02> in <module>()
----> 1 df.plot(table=True, ax=ax)
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
3669 fontsize=fontsize, colormap=colormap, table=table,
3670 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3671 sort_columns=sort_columns, **kwds)
3672 __call__.__doc__ = plot_frame.__doc__
3673
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2554 yerr=yerr, xerr=xerr,
2555 secondary_y=secondary_y, sort_columns=sort_columns,
-> 2556 **kwds)
2557
2558
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1038 axes = fig.add_subplot(111)
1039 else:
-> 1040 fig = self.ax.get_figure()
1041 if self.figsize is not None:
1042 fig.set_size_inches(self.figsize)
AttributeError: 'str' object has no attribute 'get_figure'

Also, you can pass different DataFrame
or Series
for table
keyword. The data will be drawn as displayed in print method (not transposed automatically). If required, it should be transposed manually as below example.
In [154]: fig, ax = plt.subplots(1, 1)
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-154-f6bb38fc9afd> in <module>()
----> 1 fig, ax = plt.subplots(1, 1)
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in subplots(nrows, ncols, sharex, sharey, squeeze, subplot_kw, gridspec_kw, **fig_kw)
1175 gridspec_kw = {}
1176
-> 1177 fig = figure(**fig_kw)
1178 gs = GridSpec(nrows, ncols, **gridspec_kw)
1179
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [155]: ax.get_xaxis().set_visible(False) # Hide Ticks
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-155-fa7059ff28d8> in <module>()
----> 1 ax.get_xaxis().set_visible(False) # Hide Ticks
AttributeError: 'str' object has no attribute 'get_xaxis'
In [156]: df.plot(table=np.round(df.T, 2), ax=ax)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-156-c011fd7ba0ce> in <module>()
----> 1 df.plot(table=np.round(df.T, 2), ax=ax)
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
3669 fontsize=fontsize, colormap=colormap, table=table,
3670 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3671 sort_columns=sort_columns, **kwds)
3672 __call__.__doc__ = plot_frame.__doc__
3673
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2554 yerr=yerr, xerr=xerr,
2555 secondary_y=secondary_y, sort_columns=sort_columns,
-> 2556 **kwds)
2557
2558
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1038 axes = fig.add_subplot(111)
1039 else:
-> 1040 fig = self.ax.get_figure()
1041 if self.figsize is not None:
1042 fig.set_size_inches(self.figsize)
AttributeError: 'str' object has no attribute 'get_figure'

Finally, there is a helper function pandas.tools.plotting.table
to create a table from DataFrame
and Series
, and add it to an matplotlib.Axes
. This function can accept keywords which matplotlib table has.
In [157]: from pandas.tools.plotting import table
In [158]: fig, ax = plt.subplots(1, 1)
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-158-f6bb38fc9afd> in <module>()
----> 1 fig, ax = plt.subplots(1, 1)
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in subplots(nrows, ncols, sharex, sharey, squeeze, subplot_kw, gridspec_kw, **fig_kw)
1175 gridspec_kw = {}
1176
-> 1177 fig = figure(**fig_kw)
1178 gs = GridSpec(nrows, ncols, **gridspec_kw)
1179
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [159]: table(ax, np.round(df.describe(), 2),
.....: loc='upper right', colWidths=[0.2, 0.2, 0.2])
.....:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-159-4816d5cb391f> in <module>()
1 table(ax, np.round(df.describe(), 2),
----> 2 loc='upper right', colWidths=[0.2, 0.2, 0.2])
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in table(ax, data, rowLabels, colLabels, **kwargs)
3145 import matplotlib.table
3146 table = matplotlib.table.table(ax, cellText=cellText,
-> 3147 rowLabels=rowLabels, colLabels=colLabels, **kwargs)
3148 return table
3149
/usr/lib/python2.7/dist-packages/matplotlib/table.pyc in table(ax, cellText, cellColours, cellLoc, colWidths, rowLabels, rowColours, rowLoc, colLabels, colColours, colLoc, loc, bbox, edges, **kwargs)
614
615 # Now create the table
--> 616 table = Table(ax, loc, bbox, **kwargs)
617 table.edges = edges
618 height = table._approx_text_height()
/usr/lib/python2.7/dist-packages/matplotlib/table.pyc in __init__(self, ax, loc, bbox, **kwargs)
261 if is_string_like(loc):
262 loc = self.codes.get(loc, 1)
--> 263 self.set_figure(ax.figure)
264 self._axes = ax
265 self._loc = loc
AttributeError: 'str' object has no attribute 'figure'
In [160]: df.plot(ax=ax, ylim=(0, 2), legend=None)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-160-7ef31d6a27fa> in <module>()
----> 1 df.plot(ax=ax, ylim=(0, 2), legend=None)
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
3669 fontsize=fontsize, colormap=colormap, table=table,
3670 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3671 sort_columns=sort_columns, **kwds)
3672 __call__.__doc__ = plot_frame.__doc__
3673
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2554 yerr=yerr, xerr=xerr,
2555 secondary_y=secondary_y, sort_columns=sort_columns,
-> 2556 **kwds)
2557
2558
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1038 axes = fig.add_subplot(111)
1039 else:
-> 1040 fig = self.ax.get_figure()
1041 if self.figsize is not None:
1042 fig.set_size_inches(self.figsize)
AttributeError: 'str' object has no attribute 'get_figure'

Note: You can get table instances on the axes using axes.tables
property for further decorations. See the matplotlib table documentation for more.
Colormaps¶
A potential issue when plotting a large number of columns is that it can be
difficult to distinguish some series due to repetition in the default colors. To
remedy this, DataFrame plotting supports the use of the colormap=
argument,
which accepts either a Matplotlib colormap
or a string that is a name of a colormap registered with Matplotlib. A
visualization of the default matplotlib colormaps is available here.
As matplotlib does not directly support colormaps for line-based plots, the colors are selected based on an even spacing determined by the number of columns in the DataFrame. There is no consideration made for background color, so some colormaps will produce lines that are not easily visible.
To use the cubehelix colormap, we can simply pass 'cubehelix'
to colormap=
In [161]: df = pd.DataFrame(np.random.randn(1000, 10), index=ts.index)
In [162]: df = df.cumsum()
In [163]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-163-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [164]: df.plot(colormap='cubehelix')
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-164-63d6fc8d539e> in <module>()
----> 1 df.plot(colormap='cubehelix')
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
3669 fontsize=fontsize, colormap=colormap, table=table,
3670 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3671 sort_columns=sort_columns, **kwds)
3672 __call__.__doc__ = plot_frame.__doc__
3673
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2554 yerr=yerr, xerr=xerr,
2555 secondary_y=secondary_y, sort_columns=sort_columns,
-> 2556 **kwds)
2557
2558
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

or we can pass the colormap itself
In [165]: from matplotlib import cm
In [166]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-166-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [167]: df.plot(colormap=cm.cubehelix)
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-167-b233a0eb9d3a> in <module>()
----> 1 df.plot(colormap=cm.cubehelix)
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
3669 fontsize=fontsize, colormap=colormap, table=table,
3670 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3671 sort_columns=sort_columns, **kwds)
3672 __call__.__doc__ = plot_frame.__doc__
3673
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2554 yerr=yerr, xerr=xerr,
2555 secondary_y=secondary_y, sort_columns=sort_columns,
-> 2556 **kwds)
2557
2558
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Colormaps can also be used other plot types, like bar charts:
In [168]: dd = pd.DataFrame(np.random.randn(10, 10)).applymap(abs)
In [169]: dd = dd.cumsum()
In [170]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-170-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [171]: dd.plot(kind='bar', colormap='Greens')
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-171-50ff8d167b4e> in <module>()
----> 1 dd.plot(kind='bar', colormap='Greens')
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
3669 fontsize=fontsize, colormap=colormap, table=table,
3670 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3671 sort_columns=sort_columns, **kwds)
3672 __call__.__doc__ = plot_frame.__doc__
3673
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
2554 yerr=yerr, xerr=xerr,
2555 secondary_y=secondary_y, sort_columns=sort_columns,
-> 2556 **kwds)
2557
2558
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
2382 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
2383
-> 2384 plot_obj.generate()
2385 plot_obj.draw()
2386 return plot_obj.result
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
984 self._args_adjust()
985 self._compute_plot_data()
--> 986 self._setup_subplots()
987 self._make_plot()
988 self._add_table()
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
1035 else:
1036 if self.ax is None:
-> 1037 fig = self.plt.figure(figsize=self.figsize)
1038 axes = fig.add_subplot(111)
1039 else:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Parallel coordinates charts:
In [172]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-172-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [173]: parallel_coordinates(data, 'Name', colormap='gist_rainbow')
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-173-8e1c31cb6b15> in <module>()
----> 1 parallel_coordinates(data, 'Name', colormap='gist_rainbow')
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/util/decorators.pyc in wrapper(*args, **kwargs)
87 else:
88 kwargs[new_arg_name] = new_arg_value
---> 89 return func(*args, **kwargs)
90 return wrapper
91 return _deprecate_kwarg
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/util/decorators.pyc in wrapper(*args, **kwargs)
87 else:
88 kwargs[new_arg_name] = new_arg_value
---> 89 return func(*args, **kwargs)
90 return wrapper
91 return _deprecate_kwarg
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in parallel_coordinates(frame, class_column, cols, ax, color, use_columns, xticks, colormap, axvlines, axvlines_kwds, **kwds)
709
710 if ax is None:
--> 711 ax = plt.gca()
712
713 color_values = _get_standard_colors(num_colors=len(classes),
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gca(**kwargs)
926 matplotlib.figure.Figure.gca : The figure's gca method.
927 """
--> 928 return gcf().gca(**kwargs)
929
930 # More ways of creating axes:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gcf()
576 return figManager.canvas.figure
577 else:
--> 578 return figure()
579
580
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Andrews curves charts:
In [174]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-174-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [175]: andrews_curves(data, 'Name', colormap='winter')
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-175-9949025c7e40> in <module>()
----> 1 andrews_curves(data, 'Name', colormap='winter')
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/util/decorators.pyc in wrapper(*args, **kwargs)
87 else:
88 kwargs[new_arg_name] = new_arg_value
---> 89 return func(*args, **kwargs)
90 return wrapper
91 return _deprecate_kwarg
/build/pandas-1sqeWl/pandas-0.17.1/debian/python-pandas/usr/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in andrews_curves(frame, class_column, ax, samples, color, colormap, **kwds)
557 colors = dict(zip(classes, color_values))
558 if ax is None:
--> 559 ax = plt.gca(xlim=(-pi, pi))
560 for i in range(n):
561 row = df.iloc[i].values
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gca(**kwargs)
926 matplotlib.figure.Figure.gca : The figure's gca method.
927 """
--> 928 return gcf().gca(**kwargs)
929
930 # More ways of creating axes:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gcf()
576 return figManager.canvas.figure
577 else:
--> 578 return figure()
579
580
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Plotting directly with matplotlib¶
In some situations it may still be preferable or necessary to prepare plots directly with matplotlib, for instance when a certain type of plot or customization is not (yet) supported by pandas. Series and DataFrame objects behave like arrays and can therefore be passed directly to matplotlib functions without explicit casts.
pandas also automatically registers formatters and locators that recognize date indices, thereby extending date and time support to practically all plot types available in matplotlib. Although this formatting does not provide the same level of refinement you would get when plotting via pandas, it can be faster when plotting a large number of points.
Note
The speed up for large data sets only applies to pandas 0.14.0 and later.
In [176]: price = pd.Series(np.random.randn(150).cumsum(),
.....: index=pd.date_range('2000-1-1', periods=150, freq='B'))
.....:
In [177]: ma = pd.rolling_mean(price, 20)
In [178]: mstd = pd.rolling_std(price, 20)
In [179]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-179-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [180]: plt.plot(price.index, price, 'k')
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-180-c799cff89116> in <module>()
----> 1 plt.plot(price.index, price, 'k')
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in plot(*args, **kwargs)
3145 @_autogen_docstring(Axes.plot)
3146 def plot(*args, **kwargs):
-> 3147 ax = gca()
3148 # allow callers to override the hold state by passing hold=True|False
3149 washold = ax.ishold()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gca(**kwargs)
926 matplotlib.figure.Figure.gca : The figure's gca method.
927 """
--> 928 return gcf().gca(**kwargs)
929
930 # More ways of creating axes:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gcf()
576 return figManager.canvas.figure
577 else:
--> 578 return figure()
579
580
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [181]: plt.plot(ma.index, ma, 'b')
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-181-ad69c45f1709> in <module>()
----> 1 plt.plot(ma.index, ma, 'b')
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in plot(*args, **kwargs)
3145 @_autogen_docstring(Axes.plot)
3146 def plot(*args, **kwargs):
-> 3147 ax = gca()
3148 # allow callers to override the hold state by passing hold=True|False
3149 washold = ax.ishold()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gca(**kwargs)
926 matplotlib.figure.Figure.gca : The figure's gca method.
927 """
--> 928 return gcf().gca(**kwargs)
929
930 # More ways of creating axes:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gcf()
576 return figManager.canvas.figure
577 else:
--> 578 return figure()
579
580
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [182]: plt.fill_between(mstd.index, ma-2*mstd, ma+2*mstd, color='b', alpha=0.2)
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-182-2fac449eb57b> in <module>()
----> 1 plt.fill_between(mstd.index, ma-2*mstd, ma+2*mstd, color='b', alpha=0.2)
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in fill_between(x, y1, y2, where, interpolate, step, hold, data, **kwargs)
2878 def fill_between(x, y1, y2=0, where=None, interpolate=False, step=None,
2879 hold=None, data=None, **kwargs):
-> 2880 ax = gca()
2881 # allow callers to override the hold state by passing hold=True|False
2882 washold = ax.ishold()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gca(**kwargs)
926 matplotlib.figure.Figure.gca : The figure's gca method.
927 """
--> 928 return gcf().gca(**kwargs)
929
930 # More ways of creating axes:
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gcf()
576 return figManager.canvas.figure
577 else:
--> 578 return figure()
579
580
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

Trellis plotting interface¶
Warning
The rplot
trellis plotting interface is deprecated and will be removed
in a future version. We refer to external packages like
seaborn for similar but more
refined functionality.
The docs below include some example on how to convert your existing code to
seaborn
.
Note
The tips data set can be downloaded here. Once you download it execute
tips_data = pd.read_csv('tips.csv')
from the directory where you downloaded the file.
We import the rplot API:
In [183]: import pandas.tools.rplot as rplot
Examples¶
RPlot was an API for producing Trellis plots. These plots allow you toµ arrange data in a rectangular grid by values of certain attributes. In the example below, data from the tips data set is arranged by the attributes ‘sex’ and ‘smoker’. Since both of those attributes can take on one of two values, the resulting grid has two columns and two rows. A histogram is displayed for each cell of the grid.
In [184]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-184-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [185]: plot = rplot.RPlot(tips_data, x='total_bill', y='tip')
In [186]: plot.add(rplot.TrellisGrid(['sex', 'smoker']))
In [187]: plot.add(rplot.GeomHistogram())
In [188]: plot.render(plt.gcf())
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-188-7728de29faf8> in <module>()
----> 1 plot.render(plt.gcf())
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gcf()
576 return figManager.canvas.figure
577 else:
--> 578 return figure()
579
580
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

A similar plot can be made with seaborn
using the FacetGrid
object,
resulting in the following image:
import seaborn as sns
g = sns.FacetGrid(tips_data, row="sex", col="smoker")
g.map(plt.hist, "total_bill")

Example below is the same as previous except the plot is set to kernel density
estimation. A seaborn
example is included beneath.
In [189]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-189-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [190]: plot = rplot.RPlot(tips_data, x='total_bill', y='tip')
In [191]: plot.add(rplot.TrellisGrid(['sex', 'smoker']))
In [192]: plot.add(rplot.GeomDensity())
In [193]: plot.render(plt.gcf())
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-193-7728de29faf8> in <module>()
----> 1 plot.render(plt.gcf())
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gcf()
576 return figManager.canvas.figure
577 else:
--> 578 return figure()
579
580
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

g = sns.FacetGrid(tips_data, row="sex", col="smoker")
g.map(sns.kdeplot, "total_bill")

The plot below shows that it is possible to have two or more plots for the same data displayed on the same Trellis grid cell.
In [194]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-194-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [195]: plot = rplot.RPlot(tips_data, x='total_bill', y='tip')
In [196]: plot.add(rplot.TrellisGrid(['sex', 'smoker']))
In [197]: plot.add(rplot.GeomScatter())
In [198]: plot.add(rplot.GeomPolyFit(degree=2))
In [199]: plot.render(plt.gcf())
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-199-7728de29faf8> in <module>()
----> 1 plot.render(plt.gcf())
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gcf()
576 return figManager.canvas.figure
577 else:
--> 578 return figure()
579
580
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

A seaborn equivalent for a simple scatter plot:
g = sns.FacetGrid(tips_data, row="sex", col="smoker")
g.map(plt.scatter, "total_bill", "tip")

and with a regression line, using the dedicated seaborn
regplot
function:
g = sns.FacetGrid(tips_data, row="sex", col="smoker", margin_titles=True)
g.map(sns.regplot, "total_bill", "tip", order=2)

Below is a similar plot but with 2D kernel density estimation plot superimposed,
followed by a seaborn
equivalent:
In [200]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-200-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [201]: plot = rplot.RPlot(tips_data, x='total_bill', y='tip')
In [202]: plot.add(rplot.TrellisGrid(['sex', 'smoker']))
In [203]: plot.add(rplot.GeomScatter())
In [204]: plot.add(rplot.GeomDensity2D())
In [205]: plot.render(plt.gcf())
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-205-7728de29faf8> in <module>()
----> 1 plot.render(plt.gcf())
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gcf()
576 return figManager.canvas.figure
577 else:
--> 578 return figure()
579
580
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

g = sns.FacetGrid(tips_data, row="sex", col="smoker")
g.map(plt.scatter, "total_bill", "tip")
g.map(sns.kdeplot, "total_bill", "tip")

It is possible to only use one attribute for grouping data. The example above only uses ‘sex’ attribute. If the second grouping attribute is not specified, the plots will be arranged in a column.
In [206]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-206-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [207]: plot = rplot.RPlot(tips_data, x='total_bill', y='tip')
In [208]: plot.add(rplot.TrellisGrid(['sex', '.']))
In [209]: plot.add(rplot.GeomHistogram())
In [210]: plot.render(plt.gcf())
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-210-7728de29faf8> in <module>()
----> 1 plot.render(plt.gcf())
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gcf()
576 return figManager.canvas.figure
577 else:
--> 578 return figure()
579
580
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

If the first grouping attribute is not specified the plots will be arranged in a row.
In [211]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-211-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [212]: plot = rplot.RPlot(tips_data, x='total_bill', y='tip')
In [213]: plot.add(rplot.TrellisGrid(['.', 'smoker']))
In [214]: plot.add(rplot.GeomHistogram())
In [215]: plot.render(plt.gcf())
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-215-7728de29faf8> in <module>()
----> 1 plot.render(plt.gcf())
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gcf()
576 return figManager.canvas.figure
577 else:
--> 578 return figure()
579
580
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

In seaborn
, this can also be done by only specifying one of the row
and col
arguments.
In the example below the colour and shape of the scatter plot graphical objects is mapped to ‘day’ and ‘size’ attributes respectively. You use scale objects to specify these mappings. The list of scale classes is given below with initialization arguments for quick reference.
In [216]: plt.figure()
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-216-75657f11a66b> in <module>()
----> 1 plt.figure()
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable
In [217]: plot = rplot.RPlot(tips_data, x='tip', y='total_bill')
In [218]: plot.add(rplot.TrellisGrid(['sex', 'smoker']))
In [219]: plot.add(rplot.GeomPoint(size=80.0, colour=rplot.ScaleRandomColour('day'), shape=rplot.ScaleShape('size'), alpha=1.0))
In [220]: plot.render(plt.gcf())
---------------------------------------------------------------------------
TclError Traceback (most recent call last)
<ipython-input-220-7728de29faf8> in <module>()
----> 1 plot.render(plt.gcf())
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in gcf()
576 return figManager.canvas.figure
577 else:
--> 578 return figure()
579
580
/usr/lib/python2.7/dist-packages/matplotlib/pyplot.pyc in figure(num, figsize, dpi, facecolor, edgecolor, frameon, FigureClass, **kwargs)
525 frameon=frameon,
526 FigureClass=FigureClass,
--> 527 **kwargs)
528
529 if figLabel:
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager(num, *args, **kwargs)
82 FigureClass = kwargs.pop('FigureClass', Figure)
83 figure = FigureClass(*args, **kwargs)
---> 84 return new_figure_manager_given_figure(num, figure)
85
86
/usr/lib/python2.7/dist-packages/matplotlib/backends/backend_tkagg.pyc in new_figure_manager_given_figure(num, figure)
90 """
91 _focus = windowing.FocusManager()
---> 92 window = Tk.Tk()
93 window.withdraw()
94
/usr/lib/python2.7/lib-tk/Tkinter.pyc in __init__(self, screenName, baseName, className, useTk, sync, use)
1816 baseName = baseName + ext
1817 interactive = 0
-> 1818 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
1819 if useTk:
1820 self._loadtk()
TclError: no display name and no $DISPLAY environment variable

This can also be done in seaborn
, at least for 3 variables:
g = sns.FacetGrid(tips_data, row="sex", col="smoker", hue="day")
g.map(plt.scatter, "tip", "total_bill")
g.add_legend()
