Skip to content

ENH: Allow subplots axes to be passed into DataFrame.plot() #6306

Closed
@moorepants

Description

@moorepants

This works nicely:

Python 2.7.5+ (default, Sep 19 2013, 13:48:49) 
Type "copyright", "credits" or "license" for more information.

IPython 1.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import pandas, numpy

In [2]: import matplotlib.pyplot as plt

In [3]: df1 = pandas.DataFrame(numpy.random.random((5, 4)))

In [4]: df2 = pandas.DataFrame(numpy.random.random((5, 4)))

In [5]: ax = df1.plot()

In [6]: df2.plot(ax=ax)
Out[6]: <matplotlib.axes.AxesSubplot at 0x3f4f910>

In [7]: plt.show()

But this doesn't:

In [8]: ax = df1.plot(subplots=True)

In [9]: df2.plot(subplots=True, ax=ax)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-9-70822353a5d1> in <module>()
----> 1 df2.plot(subplots=True, ax=ax)

/usr/local/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in plot_frame(frame, x, y, subplots, sharex, sharey, use_index, figsize, grid, legend, rot, ax, style, title, xlim, ylim, logx, logy, xticks, yticks, kind, sort_columns, fontsize, secondary_y, **kwds)
   1634                      logy=logy, sort_columns=sort_columns,
   1635                      secondary_y=secondary_y, **kwds)
-> 1636     plot_obj.generate()
   1637     plot_obj.draw()
   1638     if subplots:

/usr/local/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in generate(self)
    853         self._args_adjust()
    854         self._compute_plot_data()
--> 855         self._setup_subplots()
    856         self._make_plot()
    857         self._post_plot_logic()

/usr/local/lib/python2.7/dist-packages/pandas/tools/plotting.pyc in _setup_subplots(self)
    909                 ax = self._maybe_right_yaxis(ax)
    910             else:
--> 911                 fig = self.ax.get_figure()
    912                 if self.figsize is not None:
    913                     fig.set_size_inches(self.figsize)

AttributeError: 'numpy.ndarray' object has no attribute 'get_figure'

It would be nice if you could use the subplots flag, because it makes it easier to compare two data frames visually.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions