Skip to content

Commit 5ef2e4f

Browse files
FHaasegfyoung
authored andcommitted
Fix PEP-8 issues in visualization.rst (#23899)
Signed-off-by: Fabian Haase <[email protected]>
1 parent 6f25411 commit 5ef2e4f

File tree

1 file changed

+60
-42
lines changed

1 file changed

+60
-42
lines changed

doc/source/visualization.rst

+60-42
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,11 @@
66
77
import numpy as np
88
import pandas as pd
9+
910
np.random.seed(123456)
1011
np.set_printoptions(precision=4, suppress=True)
1112
pd.options.display.max_rows = 15
12-
import matplotlib
13-
# matplotlib.style.use('default')
14-
import matplotlib.pyplot as plt
15-
plt.close('all')
13+
1614
1715
*************
1816
Visualization
@@ -50,7 +48,8 @@ The ``plot`` method on Series and DataFrame is just a simple wrapper around
5048
5149
.. ipython:: python
5250
53-
ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
51+
ts = pd.Series(np.random.randn(1000),
52+
index=pd.date_range('1/1/2000', periods=1000))
5453
ts = ts.cumsum()
5554
5655
@savefig series_plot_basic.png
@@ -69,11 +68,13 @@ On DataFrame, :meth:`~DataFrame.plot` is a convenience to plot all of the column
6968
7069
.. ipython:: python
7170
72-
df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index, columns=list('ABCD'))
71+
df = pd.DataFrame(np.random.randn(1000, 4),
72+
index=ts.index, columns=list('ABCD'))
7373
df = df.cumsum()
7474
75+
plt.figure();
7576
@savefig frame_plot_basic.png
76-
plt.figure(); df.plot();
77+
df.plot();
7778
7879
You can plot one column versus another using the `x` and `y` keywords in
7980
:meth:`~DataFrame.plot`:
@@ -355,8 +356,8 @@ more complicated colorization, you can get each drawn artists by passing
355356

356357
.. ipython:: python
357358
358-
color = dict(boxes='DarkGreen', whiskers='DarkOrange',
359-
medians='DarkBlue', caps='Gray')
359+
color = {'boxes': 'DarkGreen', 'whiskers': 'DarkOrange',
360+
'medians': 'DarkBlue', 'caps': 'Gray'}
360361
361362
@savefig box_new_colorize.png
362363
df.plot.box(color=color, sym='r+')
@@ -391,7 +392,7 @@ The existing interface ``DataFrame.boxplot`` to plot boxplot still can be used.
391392
.. ipython:: python
392393
:okwarning:
393394
394-
df = pd.DataFrame(np.random.rand(10,5))
395+
df = pd.DataFrame(np.random.rand(10, 5))
395396
plt.figure();
396397
397398
@savefig box_plot_ex.png
@@ -409,8 +410,8 @@ groupings. For instance,
409410
.. ipython:: python
410411
:okwarning:
411412
412-
df = pd.DataFrame(np.random.rand(10,2), columns=['Col1', 'Col2'] )
413-
df['X'] = pd.Series(['A','A','A','A','A','B','B','B','B','B'])
413+
df = pd.DataFrame(np.random.rand(10, 2), columns=['Col1', 'Col2'])
414+
df['X'] = pd.Series(['A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B'])
414415
415416
plt.figure();
416417
@@ -429,14 +430,14 @@ columns:
429430
.. ipython:: python
430431
:okwarning:
431432
432-
df = pd.DataFrame(np.random.rand(10,3), columns=['Col1', 'Col2', 'Col3'])
433-
df['X'] = pd.Series(['A','A','A','A','A','B','B','B','B','B'])
434-
df['Y'] = pd.Series(['A','B','A','B','A','B','A','B','A','B'])
433+
df = pd.DataFrame(np.random.rand(10, 3), columns=['Col1', 'Col2', 'Col3'])
434+
df['X'] = pd.Series(['A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B'])
435+
df['Y'] = pd.Series(['A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B'])
435436
436437
plt.figure();
437438
438439
@savefig box_plot_ex3.png
439-
bp = df.boxplot(column=['Col1','Col2'], by=['X','Y'])
440+
bp = df.boxplot(column=['Col1', 'Col2'], by=['X', 'Y'])
440441
441442
.. ipython:: python
442443
:suppress:
@@ -594,7 +595,7 @@ bubble chart using a column of the ``DataFrame`` as the bubble size.
594595
.. ipython:: python
595596
596597
@savefig scatter_plot_bubble.png
597-
df.plot.scatter(x='a', y='b', s=df['c']*200);
598+
df.plot.scatter(x='a', y='b', s=df['c'] * 200);
598599
599600
.. ipython:: python
600601
:suppress:
@@ -654,8 +655,7 @@ given by column ``z``. The bins are aggregated with NumPy's ``max`` function.
654655
df['z'] = np.random.uniform(0, 3, 1000)
655656
656657
@savefig hexbin_plot_agg.png
657-
df.plot.hexbin(x='a', y='b', C='z', reduce_C_function=np.max,
658-
gridsize=25)
658+
df.plot.hexbin(x='a', y='b', C='z', reduce_C_function=np.max, gridsize=25)
659659
660660
.. ipython:: python
661661
:suppress:
@@ -682,7 +682,8 @@ A ``ValueError`` will be raised if there are any negative values in your data.
682682
683683
.. ipython:: python
684684
685-
series = pd.Series(3 * np.random.rand(4), index=['a', 'b', 'c', 'd'], name='series')
685+
series = pd.Series(3 * np.random.rand(4),
686+
index=['a', 'b', 'c', 'd'], name='series')
686687
687688
@savefig series_pie_plot.png
688689
series.plot.pie(figsize=(6, 6))
@@ -711,7 +712,8 @@ drawn in each pie plots by default; specify ``legend=False`` to hide it.
711712
712713
.. ipython:: python
713714
714-
df = pd.DataFrame(3 * np.random.rand(4, 2), index=['a', 'b', 'c', 'd'], columns=['x', 'y'])
715+
df = pd.DataFrame(3 * np.random.rand(4, 2),
716+
index=['a', 'b', 'c', 'd'], columns=['x', 'y'])
715717
716718
@savefig df_pie_plot.png
717719
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.
939941
940942
plt.figure()
941943
942-
data = pd.Series(0.1 * np.random.rand(1000) +
943-
0.9 * np.sin(np.linspace(-99 * np.pi, 99 * np.pi, num=1000)))
944+
spacing = np.linspace(-99 * np.pi, 99 * np.pi, num=1000)
945+
data = pd.Series(0.1 * np.random.rand(1000) + 0.9 * np.sin(spacing))
944946
945947
@savefig lag_plot.png
946948
lag_plot(data)
@@ -976,8 +978,8 @@ autocorrelation plots.
976978
977979
plt.figure()
978980
979-
data = pd.Series(0.7 * np.random.rand(1000) +
980-
0.3 * np.sin(np.linspace(-9 * np.pi, 9 * np.pi, num=1000)))
981+
spacing = np.linspace(-9 * np.pi, 9 * np.pi, num=1000)
982+
data = pd.Series(0.7 * np.random.rand(1000) + 0.3 * np.sin(spacing))
981983
982984
@savefig autocorrelation_plot.png
983985
autocorrelation_plot(data)
@@ -1078,8 +1080,9 @@ layout and formatting of the returned plot:
10781080

10791081
.. ipython:: python
10801082
1083+
plt.figure();
10811084
@savefig series_plot_basic2.png
1082-
plt.figure(); ts.plot(style='k--', label='Series');
1085+
ts.plot(style='k--', label='Series');
10831086
10841087
.. ipython:: python
10851088
:suppress:
@@ -1106,7 +1109,8 @@ shown by default.
11061109
11071110
.. ipython:: python
11081111
1109-
df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index, columns=list('ABCD'))
1112+
df = pd.DataFrame(np.random.randn(1000, 4),
1113+
index=ts.index, columns=list('ABCD'))
11101114
df = df.cumsum()
11111115
11121116
@savefig frame_plot_basic_noleg.png
@@ -1130,7 +1134,8 @@ You may pass ``logy`` to get a log-scale Y axis.
11301134
11311135
.. ipython:: python
11321136
1133-
ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
1137+
ts = pd.Series(np.random.randn(1000),
1138+
index=pd.date_range('1/1/2000', periods=1000))
11341139
ts = np.exp(ts.cumsum())
11351140
11361141
@savefig series_plot_logy.png
@@ -1326,14 +1331,15 @@ otherwise you will see a warning.
13261331

13271332
.. ipython:: python
13281333
1329-
fig, axes = plt.subplots(4, 4, figsize=(6, 6));
1330-
plt.subplots_adjust(wspace=0.5, hspace=0.5);
1334+
fig, axes = plt.subplots(4, 4, figsize=(6, 6))
1335+
plt.subplots_adjust(wspace=0.5, hspace=0.5)
13311336
target1 = [axes[0][0], axes[1][1], axes[2][2], axes[3][3]]
13321337
target2 = [axes[3][0], axes[2][1], axes[1][2], axes[0][3]]
13331338
13341339
df.plot(subplots=True, ax=target1, legend=False, sharex=False, sharey=False);
13351340
@savefig frame_plot_subplots_multi_ax.png
1336-
(-df).plot(subplots=True, ax=target2, legend=False, sharex=False, sharey=False);
1341+
(-df).plot(subplots=True, ax=target2, legend=False,
1342+
sharex=False, sharey=False);
13371343
13381344
.. ipython:: python
13391345
:suppress:
@@ -1346,10 +1352,12 @@ Another option is passing an ``ax`` argument to :meth:`Series.plot` to plot on a
13461352
:suppress:
13471353
13481354
np.random.seed(123456)
1349-
ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
1355+
ts = pd.Series(np.random.randn(1000),
1356+
index=pd.date_range('1/1/2000', periods=1000))
13501357
ts = ts.cumsum()
13511358
1352-
df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index, columns=list('ABCD'))
1359+
df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index,
1360+
columns=list('ABCD'))
13531361
df = df.cumsum()
13541362
13551363
.. ipython:: python
@@ -1360,12 +1368,15 @@ Another option is passing an ``ax`` argument to :meth:`Series.plot` to plot on a
13601368
.. ipython:: python
13611369
13621370
fig, axes = plt.subplots(nrows=2, ncols=2)
1363-
df['A'].plot(ax=axes[0,0]); axes[0,0].set_title('A');
1364-
df['B'].plot(ax=axes[0,1]); axes[0,1].set_title('B');
1365-
df['C'].plot(ax=axes[1,0]); axes[1,0].set_title('C');
1366-
1371+
df['A'].plot(ax=axes[0, 0]);
1372+
axes[0, 0].set_title('A');
1373+
df['B'].plot(ax=axes[0, 1]);
1374+
axes[0, 1].set_title('B');
1375+
df['C'].plot(ax=axes[1, 0]);
1376+
axes[1, 0].set_title('C');
1377+
df['D'].plot(ax=axes[1, 1]);
13671378
@savefig series_plot_multi.png
1368-
df['D'].plot(ax=axes[1,1]); axes[1,1].set_title('D');
1379+
axes[1, 1].set_title('D');
13691380
13701381
.. ipython:: python
13711382
:suppress:
@@ -1392,10 +1403,16 @@ Here is an example of one way to easily plot group means with standard deviation
13921403
.. ipython:: python
13931404
13941405
# Generate the data
1395-
ix3 = pd.MultiIndex.from_arrays([['a', 'a', 'a', 'a', 'b', 'b', 'b', 'b'], ['foo', 'foo', 'bar', 'bar', 'foo', 'foo', 'bar', 'bar']], names=['letter', 'word'])
1396-
df3 = pd.DataFrame({'data1': [3, 2, 4, 3, 2, 4, 3, 2], 'data2': [6, 5, 7, 5, 4, 5, 6, 5]}, index=ix3)
1406+
ix3 = pd.MultiIndex.from_arrays([
1407+
['a', 'a', 'a', 'a', 'b', 'b', 'b', 'b'],
1408+
['foo', 'foo', 'bar', 'bar', 'foo', 'foo', 'bar', 'bar']],
1409+
names=['letter', 'word'])
1410+
1411+
df3 = pd.DataFrame({'data1': [3, 2, 4, 3, 2, 4, 3, 2],
1412+
'data2': [6, 5, 7, 5, 4, 5, 6, 5]}, index=ix3)
13971413
1398-
# Group by index labels and take the means and standard deviations for each group
1414+
# Group by index labels and take the means and standard deviations
1415+
# for each group
13991416
gp3 = df3.groupby(level=('letter', 'word'))
14001417
means = gp3.mean()
14011418
errors = gp3.std()
@@ -1616,7 +1633,8 @@ when plotting a large number of points.
16161633
plt.plot(price.index, price, 'k')
16171634
plt.plot(ma.index, ma, 'b')
16181635
@savefig bollinger.png
1619-
plt.fill_between(mstd.index, ma-2*mstd, ma+2*mstd, color='b', alpha=0.2)
1636+
plt.fill_between(mstd.index, ma - 2 * mstd, ma + 2 * mstd,
1637+
color='b', alpha=0.2)
16201638
16211639
.. ipython:: python
16221640
:suppress:

0 commit comments

Comments
 (0)