Skip to content

Commit 767041a

Browse files
committed
Update documentation on visualization to mention using pandas objects directly with matplotlib and the automatically installed date and time formatter.
1 parent 2e13849 commit 767041a

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

doc/source/visualization.rst

+47-3
Original file line numberDiff line numberDiff line change
@@ -617,9 +617,18 @@ be colored differently.
617617
Colormaps
618618
~~~~~~~~~
619619

620-
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 <http://matplotlib.org/api/cm_api.html>`__ or a string that is a name of a colormap registered with Matplotlib. A visualization of the default matplotlib colormaps is available `here <http://wiki.scipy.org/Cookbook/Matplotlib/Show_colormaps>`__.
621-
622-
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.
620+
A potential issue when plotting a large number of columns is that it can be
621+
difficult to distinguish some series due to repetition in the default colors. To
622+
remedy this, DataFrame plotting supports the use of the ``colormap=`` argument,
623+
which accepts either a Matplotlib `colormap <http://matplotlib.org/api/cm_api.html>`__
624+
or a string that is a name of a colormap registered with Matplotlib. A
625+
visualization of the default matplotlib colormaps is available `here
626+
<http://wiki.scipy.org/Cookbook/Matplotlib/Show_colormaps>`__.
627+
628+
As matplotlib does not directly support colormaps for line-based plots, the
629+
colors are selected based on an even spacing determined by the number of columns
630+
in the DataFrame. There is no consideration made for background color, so some
631+
colormaps will produce lines that are not easily visible.
623632

624633
To use the jet colormap, we can simply pass ``'jet'`` to ``colormap=``
625634

@@ -674,7 +683,42 @@ Andrews curves charts:
674683
@savefig andrews_curve_winter.png
675684
andrews_curves(data, 'Name', colormap='winter')
676685
686+
Plotting directly with matplotlib
687+
---------------------------------
688+
689+
In some situations it may still be preferable or necessary to prepare plots
690+
directly with matplotlib, for instance when a certain type of plot or
691+
customization is not (yet) supported by pandas. Series and DataFrame objects
692+
behave like arrays and can therefore be passed directly to matplotlib functions
693+
without explicit casts.
694+
695+
Pandas also automatically registers formatters and locators that recognize date
696+
indices, thereby extending date and time support to practically all plot types
697+
available in matplotlib. Although this formatting does not provide the same
698+
level of refinement you would get when plotting via pandas, it can be faster
699+
when plotting a large number of points.
700+
701+
.. note::
702+
703+
The speed up for large data sets only applies to pandas 0.14.0 and later.
704+
705+
706+
.. ipython:: python
707+
708+
price = Series(randn(150).cumsum(),
709+
index=date_range('2000-1-1', periods=150, freq='B'))
710+
ma = pd.rolling_mean(price, 20)
711+
mstd = pd.rolling_std(price, 20)
712+
713+
plt.figure()
714+
715+
plt.plot(price.index, price, 'k')
716+
plt.plot(ma.index, ma, 'b')
717+
@savefig bollinger.png
718+
plt.fill_between(mstd.index, ma-2*mstd, ma+2*mstd, color='b', alpha=0.2)
719+
677720
.. ipython:: python
678721
:suppress:
679722
680723
plt.close('all')
724+

0 commit comments

Comments
 (0)