From 3cc9bb79a7c822118b736a14838e7badba187d2f Mon Sep 17 00:00:00 2001 From: Fabian Haase Date: Sun, 25 Nov 2018 17:57:31 +0100 Subject: [PATCH] Fix PEP-8 issues in visualization.rst Signed-off-by: Fabian Haase --- doc/source/visualization.rst | 102 ++++++++++++++++++++--------------- 1 file changed, 60 insertions(+), 42 deletions(-) diff --git a/doc/source/visualization.rst b/doc/source/visualization.rst index dd8ccfcfd28ac..050d754d0ac8b 100644 --- a/doc/source/visualization.rst +++ b/doc/source/visualization.rst @@ -6,13 +6,11 @@ import numpy as np import pandas as pd + np.random.seed(123456) np.set_printoptions(precision=4, suppress=True) pd.options.display.max_rows = 15 - import matplotlib - # matplotlib.style.use('default') - import matplotlib.pyplot as plt - plt.close('all') + ************* Visualization @@ -50,7 +48,8 @@ The ``plot`` method on Series and DataFrame is just a simple wrapper around .. ipython:: python - ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000)) + ts = pd.Series(np.random.randn(1000), + index=pd.date_range('1/1/2000', periods=1000)) ts = ts.cumsum() @savefig series_plot_basic.png @@ -69,11 +68,13 @@ On DataFrame, :meth:`~DataFrame.plot` is a convenience to plot all of the column .. ipython:: python - df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index, columns=list('ABCD')) + df = pd.DataFrame(np.random.randn(1000, 4), + index=ts.index, columns=list('ABCD')) df = df.cumsum() + plt.figure(); @savefig frame_plot_basic.png - plt.figure(); df.plot(); + df.plot(); You can plot one column versus another using the `x` and `y` keywords in :meth:`~DataFrame.plot`: @@ -355,8 +356,8 @@ more complicated colorization, you can get each drawn artists by passing .. ipython:: python - color = dict(boxes='DarkGreen', whiskers='DarkOrange', - medians='DarkBlue', caps='Gray') + color = {'boxes': 'DarkGreen', 'whiskers': 'DarkOrange', + 'medians': 'DarkBlue', 'caps': 'Gray'} @savefig box_new_colorize.png df.plot.box(color=color, sym='r+') @@ -391,7 +392,7 @@ The existing interface ``DataFrame.boxplot`` to plot boxplot still can be used. .. ipython:: python :okwarning: - df = pd.DataFrame(np.random.rand(10,5)) + df = pd.DataFrame(np.random.rand(10, 5)) plt.figure(); @savefig box_plot_ex.png @@ -409,8 +410,8 @@ groupings. For instance, .. ipython:: python :okwarning: - df = pd.DataFrame(np.random.rand(10,2), columns=['Col1', 'Col2'] ) - df['X'] = pd.Series(['A','A','A','A','A','B','B','B','B','B']) + df = pd.DataFrame(np.random.rand(10, 2), columns=['Col1', 'Col2']) + df['X'] = pd.Series(['A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B']) plt.figure(); @@ -429,14 +430,14 @@ columns: .. ipython:: python :okwarning: - df = pd.DataFrame(np.random.rand(10,3), columns=['Col1', 'Col2', 'Col3']) - df['X'] = pd.Series(['A','A','A','A','A','B','B','B','B','B']) - df['Y'] = pd.Series(['A','B','A','B','A','B','A','B','A','B']) + df = pd.DataFrame(np.random.rand(10, 3), columns=['Col1', 'Col2', 'Col3']) + df['X'] = pd.Series(['A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B']) + df['Y'] = pd.Series(['A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B']) plt.figure(); @savefig box_plot_ex3.png - bp = df.boxplot(column=['Col1','Col2'], by=['X','Y']) + bp = df.boxplot(column=['Col1', 'Col2'], by=['X', 'Y']) .. ipython:: python :suppress: @@ -594,7 +595,7 @@ bubble chart using a column of the ``DataFrame`` as the bubble size. .. ipython:: python @savefig scatter_plot_bubble.png - df.plot.scatter(x='a', y='b', s=df['c']*200); + df.plot.scatter(x='a', y='b', s=df['c'] * 200); .. ipython:: python :suppress: @@ -654,8 +655,7 @@ given by column ``z``. The bins are aggregated with NumPy's ``max`` function. df['z'] = np.random.uniform(0, 3, 1000) @savefig hexbin_plot_agg.png - df.plot.hexbin(x='a', y='b', C='z', reduce_C_function=np.max, - gridsize=25) + df.plot.hexbin(x='a', y='b', C='z', reduce_C_function=np.max, gridsize=25) .. ipython:: python :suppress: @@ -682,7 +682,8 @@ A ``ValueError`` will be raised if there are any negative values in your data. .. ipython:: python - series = pd.Series(3 * np.random.rand(4), index=['a', 'b', 'c', 'd'], name='series') + series = pd.Series(3 * np.random.rand(4), + index=['a', 'b', 'c', 'd'], name='series') @savefig series_pie_plot.png series.plot.pie(figsize=(6, 6)) @@ -711,7 +712,8 @@ drawn in each pie plots by default; specify ``legend=False`` to hide it. .. ipython:: python - df = pd.DataFrame(3 * np.random.rand(4, 2), index=['a', 'b', 'c', 'd'], columns=['x', 'y']) + df = pd.DataFrame(3 * np.random.rand(4, 2), + index=['a', 'b', 'c', 'd'], columns=['x', 'y']) @savefig df_pie_plot.png df.plot.pie(subplots=True, figsize=(8, 4)) @@ -939,8 +941,8 @@ be passed, and when ``lag=1`` the plot is essentially ``data[:-1]`` vs. plt.figure() - data = pd.Series(0.1 * np.random.rand(1000) + - 0.9 * np.sin(np.linspace(-99 * np.pi, 99 * np.pi, num=1000))) + spacing = np.linspace(-99 * np.pi, 99 * np.pi, num=1000) + data = pd.Series(0.1 * np.random.rand(1000) + 0.9 * np.sin(spacing)) @savefig lag_plot.png lag_plot(data) @@ -976,8 +978,8 @@ autocorrelation plots. plt.figure() - data = pd.Series(0.7 * np.random.rand(1000) + - 0.3 * np.sin(np.linspace(-9 * np.pi, 9 * np.pi, num=1000))) + spacing = np.linspace(-9 * np.pi, 9 * np.pi, num=1000) + data = pd.Series(0.7 * np.random.rand(1000) + 0.3 * np.sin(spacing)) @savefig autocorrelation_plot.png autocorrelation_plot(data) @@ -1078,8 +1080,9 @@ layout and formatting of the returned plot: .. ipython:: python + plt.figure(); @savefig series_plot_basic2.png - plt.figure(); ts.plot(style='k--', label='Series'); + ts.plot(style='k--', label='Series'); .. ipython:: python :suppress: @@ -1106,7 +1109,8 @@ shown by default. .. ipython:: python - df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index, columns=list('ABCD')) + df = pd.DataFrame(np.random.randn(1000, 4), + index=ts.index, columns=list('ABCD')) df = df.cumsum() @savefig frame_plot_basic_noleg.png @@ -1130,7 +1134,8 @@ You may pass ``logy`` to get a log-scale Y axis. .. ipython:: python - ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000)) + ts = pd.Series(np.random.randn(1000), + index=pd.date_range('1/1/2000', periods=1000)) ts = np.exp(ts.cumsum()) @savefig series_plot_logy.png @@ -1326,14 +1331,15 @@ otherwise you will see a warning. .. ipython:: python - fig, axes = plt.subplots(4, 4, figsize=(6, 6)); - plt.subplots_adjust(wspace=0.5, hspace=0.5); + fig, axes = plt.subplots(4, 4, figsize=(6, 6)) + plt.subplots_adjust(wspace=0.5, hspace=0.5) target1 = [axes[0][0], axes[1][1], axes[2][2], axes[3][3]] target2 = [axes[3][0], axes[2][1], axes[1][2], axes[0][3]] df.plot(subplots=True, ax=target1, legend=False, sharex=False, sharey=False); @savefig frame_plot_subplots_multi_ax.png - (-df).plot(subplots=True, ax=target2, legend=False, sharex=False, sharey=False); + (-df).plot(subplots=True, ax=target2, legend=False, + sharex=False, sharey=False); .. ipython:: python :suppress: @@ -1346,10 +1352,12 @@ Another option is passing an ``ax`` argument to :meth:`Series.plot` to plot on a :suppress: np.random.seed(123456) - ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000)) + ts = pd.Series(np.random.randn(1000), + index=pd.date_range('1/1/2000', periods=1000)) ts = ts.cumsum() - df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index, columns=list('ABCD')) + df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index, + columns=list('ABCD')) df = df.cumsum() .. ipython:: python @@ -1360,12 +1368,15 @@ Another option is passing an ``ax`` argument to :meth:`Series.plot` to plot on a .. ipython:: python fig, axes = plt.subplots(nrows=2, ncols=2) - df['A'].plot(ax=axes[0,0]); axes[0,0].set_title('A'); - df['B'].plot(ax=axes[0,1]); axes[0,1].set_title('B'); - df['C'].plot(ax=axes[1,0]); axes[1,0].set_title('C'); - + df['A'].plot(ax=axes[0, 0]); + axes[0, 0].set_title('A'); + df['B'].plot(ax=axes[0, 1]); + axes[0, 1].set_title('B'); + df['C'].plot(ax=axes[1, 0]); + axes[1, 0].set_title('C'); + df['D'].plot(ax=axes[1, 1]); @savefig series_plot_multi.png - df['D'].plot(ax=axes[1,1]); axes[1,1].set_title('D'); + axes[1, 1].set_title('D'); .. ipython:: python :suppress: @@ -1392,10 +1403,16 @@ Here is an example of one way to easily plot group means with standard deviation .. ipython:: python # Generate the data - ix3 = pd.MultiIndex.from_arrays([['a', 'a', 'a', 'a', 'b', 'b', 'b', 'b'], ['foo', 'foo', 'bar', 'bar', 'foo', 'foo', 'bar', 'bar']], names=['letter', 'word']) - df3 = pd.DataFrame({'data1': [3, 2, 4, 3, 2, 4, 3, 2], 'data2': [6, 5, 7, 5, 4, 5, 6, 5]}, index=ix3) + ix3 = pd.MultiIndex.from_arrays([ + ['a', 'a', 'a', 'a', 'b', 'b', 'b', 'b'], + ['foo', 'foo', 'bar', 'bar', 'foo', 'foo', 'bar', 'bar']], + names=['letter', 'word']) + + 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 + # Group by index labels and take the means and standard deviations + # for each group gp3 = df3.groupby(level=('letter', 'word')) means = gp3.mean() errors = gp3.std() @@ -1616,7 +1633,8 @@ when plotting a large number of points. plt.plot(price.index, price, 'k') plt.plot(ma.index, ma, 'b') @savefig bollinger.png - plt.fill_between(mstd.index, ma-2*mstd, ma+2*mstd, color='b', alpha=0.2) + plt.fill_between(mstd.index, ma - 2 * mstd, ma + 2 * mstd, + color='b', alpha=0.2) .. ipython:: python :suppress: