Skip to content

Commit 92862c5

Browse files
committed
Review datapythonista for file timeseries.rst
Signed-off-by: Fabian Haase <[email protected]>
1 parent e980af2 commit 92862c5

File tree

1 file changed

+44
-44
lines changed

1 file changed

+44
-44
lines changed

doc/source/visualization.rst

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,15 @@
22
.. _visualization:
33

44
.. ipython:: python
5-
:flake8-add-ignore: E702, E703
5+
:flake8-add-ignore: E702, # multiple statements on one line. Needed for @savefig
66
:suppress:
77
88
import numpy as np
99
import pandas as pd
1010
11-
import matplotlib # noqa: F401
12-
# matplotlib.style.use('default')
13-
import matplotlib.pyplot as plt
14-
1511
np.random.seed(123456)
1612
np.set_printoptions(precision=4, suppress=True)
1713
pd.options.display.max_rows = 15
18-
plt.close('all')
1914
2015
2116
*************
@@ -25,11 +20,14 @@ Visualization
2520
We use the standard convention for referencing the matplotlib API:
2621

2722
.. ipython:: python
28-
:flake8-group: None
29-
:flake8-set-ignore: F401
3023
3124
import matplotlib.pyplot as plt
3225
26+
.. ipython:: python
27+
:suppress:
28+
29+
plt.close('all')
30+
3331
We provide the basics in pandas to easily create decent looking plots.
3432
See the :ref:`ecosystem <ecosystem.visualization>` section for visualization
3533
libraries that go beyond the basics documented here.
@@ -81,7 +79,8 @@ On DataFrame, :meth:`~DataFrame.plot` is a convenience to plot all of the column
8179
df = df.cumsum()
8280
8381
@savefig frame_plot_basic.png
84-
plt.figure(); df.plot();
82+
plt.figure()
83+
df.plot()
8584
8685
You can plot one column versus another using the `x` and `y` keywords in
8786
:meth:`~DataFrame.plot`:
@@ -133,21 +132,22 @@ For example, a bar plot can be created the following way:
133132

134133
.. ipython:: python
135134
136-
plt.figure();
135+
plt.figure()
137136
138137
@savefig bar_plot_ex.png
139-
df.iloc[5].plot(kind='bar');
138+
df.iloc[5].plot(kind='bar')
140139
141140
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:
142141

143142
.. ipython::
144143
:flake8-group: None
145-
:flake8-add-ignore: E999, E225, F821
144+
:flake8-add-ignore: E999, E225, F821, # E999 breaks linting for complete block
146145
:verbatim:
147146

148-
In [14]: df = pd.DataFrame()
147+
In [0]: df = pd.DataFrame()
149148

150-
In [15]: df.plot.<TAB>
149+
In [1]: df.plot.<TAB>
150+
Out[1]:
151151
df.plot.area df.plot.barh df.plot.density df.plot.hist df.plot.line df.plot.scatter
152152
df.plot.bar df.plot.box df.plot.hexbin df.plot.kde df.plot.pie
153153

@@ -178,7 +178,7 @@ For labeled, non-time series data, you may wish to produce a bar plot:
178178

179179
.. ipython:: python
180180
181-
plt.figure();
181+
plt.figure()
182182
183183
@savefig bar_plot_ex.png
184184
df.iloc[5].plot.bar(); plt.axhline(0, color='k')
@@ -198,7 +198,7 @@ bar plot:
198198
df2 = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd'])
199199
200200
@savefig bar_plot_multi_ex.png
201-
df2.plot.bar();
201+
df2.plot.bar()
202202
203203
To produce a stacked bar plot, pass ``stacked=True``:
204204

@@ -211,7 +211,7 @@ To produce a stacked bar plot, pass ``stacked=True``:
211211
.. ipython:: python
212212
213213
@savefig bar_plot_stacked_ex.png
214-
df2.plot.bar(stacked=True);
214+
df2.plot.bar(stacked=True)
215215
216216
To get horizontal bar plots, use the ``barh`` method:
217217

@@ -224,7 +224,7 @@ To get horizontal bar plots, use the ``barh`` method:
224224
.. ipython:: python
225225
226226
@savefig barh_plot_stacked_ex.png
227-
df2.plot.barh(stacked=True);
227+
df2.plot.barh(stacked=True)
228228
229229
.. _visualization.hist:
230230

@@ -238,7 +238,7 @@ Histograms can be drawn by using the :meth:`DataFrame.plot.hist` and :meth:`Seri
238238
df4 = pd.DataFrame({'a': np.random.randn(1000) + 1, 'b': np.random.randn(1000),
239239
'c': np.random.randn(1000) - 1}, columns=['a', 'b', 'c'])
240240
241-
plt.figure();
241+
plt.figure()
242242
243243
@savefig hist_new.png
244244
df4.plot.hist(alpha=0.5)
@@ -254,7 +254,7 @@ using the ``bins`` keyword.
254254

255255
.. ipython:: python
256256
257-
plt.figure();
257+
plt.figure()
258258
259259
@savefig hist_new_stacked.png
260260
df4.plot.hist(stacked=True, bins=20)
@@ -270,7 +270,7 @@ horizontal and cumulative histograms can be drawn by
270270

271271
.. ipython:: python
272272
273-
plt.figure();
273+
plt.figure()
274274
275275
@savefig hist_new_kwargs.png
276276
df4['a'].plot.hist(orientation='horizontal', cumulative=True)
@@ -288,7 +288,7 @@ The existing interface ``DataFrame.hist`` to plot histogram still can be used.
288288

289289
.. ipython:: python
290290
291-
plt.figure();
291+
plt.figure()
292292
293293
@savefig hist_plot_ex.png
294294
df['A'].diff().hist()
@@ -402,7 +402,7 @@ The existing interface ``DataFrame.boxplot`` to plot boxplot still can be used.
402402
:okwarning:
403403
404404
df = pd.DataFrame(np.random.rand(10, 5))
405-
plt.figure();
405+
plt.figure()
406406
407407
@savefig box_plot_ex.png
408408
bp = df.boxplot()
@@ -422,7 +422,7 @@ groupings. For instance,
422422
df = pd.DataFrame(np.random.rand(10, 2), columns=['Col1', 'Col2'])
423423
df['X'] = pd.Series(['A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B'])
424424
425-
plt.figure();
425+
plt.figure()
426426
427427
@savefig box_plot_ex2.png
428428
bp = df.boxplot(by='X')
@@ -443,7 +443,7 @@ columns:
443443
df['X'] = pd.Series(['A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B'])
444444
df['Y'] = pd.Series(['A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B'])
445445
446-
plt.figure();
446+
plt.figure()
447447
448448
@savefig box_plot_ex3.png
449449
bp = df.boxplot(column=['Col1', 'Col2'], by=['X', 'Y'])
@@ -531,7 +531,7 @@ When input data contains `NaN`, it will be automatically filled by 0. If you wan
531531
df = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd'])
532532
533533
@savefig area_plot_stacked.png
534-
df.plot.area();
534+
df.plot.area()
535535
536536
To produce an unstacked plot, pass ``stacked=False``. Alpha value is set to 0.5 unless otherwise specified:
537537

@@ -544,7 +544,7 @@ To produce an unstacked plot, pass ``stacked=False``. Alpha value is set to 0.5
544544
.. ipython:: python
545545
546546
@savefig area_plot_unstacked.png
547-
df.plot.area(stacked=False);
547+
df.plot.area(stacked=False)
548548
549549
.. _visualization.scatter:
550550

@@ -567,16 +567,16 @@ These can be specified by the ``x`` and ``y`` keywords.
567567
df = pd.DataFrame(np.random.rand(50, 4), columns=['a', 'b', 'c', 'd'])
568568
569569
@savefig scatter_plot.png
570-
df.plot.scatter(x='a', y='b');
570+
df.plot.scatter(x='a', y='b')
571571
572572
To plot multiple column groups in a single axes, repeat ``plot`` method specifying target ``ax``.
573573
It is recommended to specify ``color`` and ``label`` keywords to distinguish each groups.
574574

575575
.. ipython:: python
576576
577-
ax = df.plot.scatter(x='a', y='b', color='DarkBlue', label='Group 1');
577+
ax = df.plot.scatter(x='a', y='b', color='DarkBlue', label='Group 1')
578578
@savefig scatter_plot_repeated.png
579-
df.plot.scatter(x='c', y='d', color='DarkGreen', label='Group 2', ax=ax);
579+
df.plot.scatter(x='c', y='d', color='DarkGreen', label='Group 2', ax=ax)
580580
581581
.. ipython:: python
582582
:suppress:
@@ -589,7 +589,7 @@ each point:
589589
.. ipython:: python
590590
591591
@savefig scatter_plot_colored.png
592-
df.plot.scatter(x='a', y='b', c='c', s=50);
592+
df.plot.scatter(x='a', y='b', c='c', s=50)
593593
594594
595595
.. ipython:: python
@@ -604,7 +604,7 @@ bubble chart using a column of the ``DataFrame`` as the bubble size.
604604
.. ipython:: python
605605
606606
@savefig scatter_plot_bubble.png
607-
df.plot.scatter(x='a', y='b', s=df['c'] * 200);
607+
df.plot.scatter(x='a', y='b', s=df['c'] * 200)
608608
609609
.. ipython:: python
610610
:suppress:
@@ -1091,7 +1091,7 @@ layout and formatting of the returned plot:
10911091
.. ipython:: python
10921092
10931093
@savefig series_plot_basic2.png
1094-
plt.figure(); ts.plot(style='k--', label='Series');
1094+
plt.figure(); ts.plot(style='k--', label='Series')
10951095
10961096
.. ipython:: python
10971097
:suppress:
@@ -1286,7 +1286,7 @@ with the ``subplots`` keyword:
12861286
.. ipython:: python
12871287
12881288
@savefig frame_plot_subplots.png
1289-
df.plot(subplots=True, figsize=(6, 6));
1289+
df.plot(subplots=True, figsize=(6, 6))
12901290
12911291
.. ipython:: python
12921292
:suppress:
@@ -1309,7 +1309,7 @@ or columns needed, given the other.
13091309
.. ipython:: python
13101310
13111311
@savefig frame_plot_subplots_layout.png
1312-
df.plot(subplots=True, layout=(2, 3), figsize=(6, 6), sharex=False);
1312+
df.plot(subplots=True, layout=(2, 3), figsize=(6, 6), sharex=False)
13131313
13141314
.. ipython:: python
13151315
:suppress:
@@ -1320,7 +1320,7 @@ The above example is identical to using:
13201320

13211321
.. ipython:: python
13221322
1323-
df.plot(subplots=True, layout=(2, -1), figsize=(6, 6), sharex=False);
1323+
df.plot(subplots=True, layout=(2, -1), figsize=(6, 6), sharex=False)
13241324
13251325
.. ipython:: python
13261326
:suppress:
@@ -1340,15 +1340,15 @@ otherwise you will see a warning.
13401340

13411341
.. ipython:: python
13421342
1343-
fig, axes = plt.subplots(4, 4, figsize=(6, 6));
1344-
plt.subplots_adjust(wspace=0.5, hspace=0.5);
1343+
fig, axes = plt.subplots(4, 4, figsize=(6, 6))
1344+
plt.subplots_adjust(wspace=0.5, hspace=0.5)
13451345
target1 = [axes[0][0], axes[1][1], axes[2][2], axes[3][3]]
13461346
target2 = [axes[3][0], axes[2][1], axes[1][2], axes[0][3]]
13471347
1348-
df.plot(subplots=True, ax=target1, legend=False, sharex=False, sharey=False);
1348+
df.plot(subplots=True, ax=target1, legend=False, sharex=False, sharey=False)
13491349
@savefig frame_plot_subplots_multi_ax.png
13501350
(-df).plot(subplots=True, ax=target2, legend=False,
1351-
sharex=False, sharey=False);
1351+
sharex=False, sharey=False)
13521352
13531353
.. ipython:: python
13541354
:suppress:
@@ -1377,12 +1377,12 @@ Another option is passing an ``ax`` argument to :meth:`Series.plot` to plot on a
13771377
.. ipython:: python
13781378
13791379
fig, axes = plt.subplots(nrows=2, ncols=2)
1380-
df['A'].plot(ax=axes[0, 0]); axes[0, 0].set_title('A');
1381-
df['B'].plot(ax=axes[0, 1]); axes[0, 1].set_title('B');
1382-
df['C'].plot(ax=axes[1, 0]); axes[1, 0].set_title('C');
1380+
df['A'].plot(ax=axes[0, 0]); axes[0, 0].set_title('A')
1381+
df['B'].plot(ax=axes[0, 1]); axes[0, 1].set_title('B')
1382+
df['C'].plot(ax=axes[1, 0]); axes[1, 0].set_title('C')
13831383
13841384
@savefig series_plot_multi.png
1385-
df['D'].plot(ax=axes[1, 1]); axes[1, 1].set_title('D');
1385+
df['D'].plot(ax=axes[1, 1]); axes[1, 1].set_title('D')
13861386
13871387
.. ipython:: python
13881388
:suppress:

0 commit comments

Comments
 (0)