Skip to content

Commit cecddea

Browse files
committed
Remove plt.figure()
calling plt.figure() doesn't change outputted graphs. Therefore it's not needed. Signed-off-by: Fabian Haase <[email protected]>
1 parent 08ea35c commit cecddea

File tree

1 file changed

+1
-78
lines changed

1 file changed

+1
-78
lines changed

doc/source/visualization.rst

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ On DataFrame, :meth:`~DataFrame.plot` is a convenience to plot all of the column
7979
df = df.cumsum()
8080
8181
@savefig frame_plot_basic.png
82-
plt.figure()
8382
df.plot()
8483
8584
You can plot one column versus another using the `x` and `y` keywords in
@@ -89,7 +88,6 @@ You can plot one column versus another using the `x` and `y` keywords in
8988
:suppress:
9089
9190
plt.close('all')
92-
plt.figure()
9391
np.random.seed(123456)
9492
9593
.. ipython:: python
@@ -132,8 +130,6 @@ For example, a bar plot can be created the following way:
132130

133131
.. ipython:: python
134132
135-
plt.figure()
136-
137133
@savefig bar_plot_ex.png
138134
df.iloc[5].plot(kind='bar')
139135
@@ -178,8 +174,6 @@ For labeled, non-time series data, you may wish to produce a bar plot:
178174

179175
.. ipython:: python
180176
181-
plt.figure()
182-
183177
@savefig bar_plot_ex.png
184178
df.iloc[5].plot.bar(); plt.axhline(0, color='k')
185179
@@ -190,7 +184,6 @@ bar plot:
190184
:suppress:
191185
192186
plt.close('all')
193-
plt.figure()
194187
np.random.seed(123456)
195188
196189
.. ipython:: python
@@ -206,7 +199,6 @@ To produce a stacked bar plot, pass ``stacked=True``:
206199
:suppress:
207200
208201
plt.close('all')
209-
plt.figure()
210202
211203
.. ipython:: python
212204
@@ -219,7 +211,6 @@ To get horizontal bar plots, use the ``barh`` method:
219211
:suppress:
220212
221213
plt.close('all')
222-
plt.figure()
223214
224215
.. ipython:: python
225216
@@ -238,8 +229,6 @@ Histograms can be drawn by using the :meth:`DataFrame.plot.hist` and :meth:`Seri
238229
df4 = pd.DataFrame({'a': np.random.randn(1000) + 1, 'b': np.random.randn(1000),
239230
'c': np.random.randn(1000) - 1}, columns=['a', 'b', 'c'])
240231
241-
plt.figure()
242-
243232
@savefig hist_new.png
244233
df4.plot.hist(alpha=0.5)
245234
@@ -254,8 +243,6 @@ using the ``bins`` keyword.
254243

255244
.. ipython:: python
256245
257-
plt.figure()
258-
259246
@savefig hist_new_stacked.png
260247
df4.plot.hist(stacked=True, bins=20)
261248
@@ -270,8 +257,6 @@ horizontal and cumulative histograms can be drawn by
270257

271258
.. ipython:: python
272259
273-
plt.figure()
274-
275260
@savefig hist_new_kwargs.png
276261
df4['a'].plot.hist(orientation='horizontal', cumulative=True)
277262
@@ -288,8 +273,6 @@ The existing interface ``DataFrame.hist`` to plot histogram still can be used.
288273

289274
.. ipython:: python
290275
291-
plt.figure()
292-
293276
@savefig hist_plot_ex.png
294277
df['A'].diff().hist()
295278
@@ -303,8 +286,6 @@ subplots:
303286

304287
.. ipython:: python
305288
306-
plt.figure()
307-
308289
@savefig frame_hist_ex.png
309290
df.diff().hist(color='k', alpha=0.5, bins=50)
310291
@@ -315,7 +296,6 @@ The ``by`` keyword can be specified to plot grouped histograms:
315296
:suppress:
316297
317298
plt.close('all')
318-
plt.figure()
319299
np.random.seed(123456)
320300
321301
.. ipython:: python
@@ -402,7 +382,6 @@ The existing interface ``DataFrame.boxplot`` to plot boxplot still can be used.
402382
:okwarning:
403383
404384
df = pd.DataFrame(np.random.rand(10, 5))
405-
plt.figure()
406385
407386
@savefig box_plot_ex.png
408387
bp = df.boxplot()
@@ -422,8 +401,6 @@ groupings. For instance,
422401
df = pd.DataFrame(np.random.rand(10, 2), columns=['Col1', 'Col2'])
423402
df['X'] = pd.Series(['A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B'])
424403
425-
plt.figure()
426-
427404
@savefig box_plot_ex2.png
428405
bp = df.boxplot(by='X')
429406
@@ -443,8 +420,6 @@ columns:
443420
df['X'] = pd.Series(['A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B'])
444421
df['Y'] = pd.Series(['A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 'A', 'B'])
445422
446-
plt.figure()
447-
448423
@savefig box_plot_ex3.png
449424
bp = df.boxplot(column=['Col1', 'Col2'], by=['X', 'Y'])
450425
@@ -524,7 +499,6 @@ When input data contains `NaN`, it will be automatically filled by 0. If you wan
524499
:suppress:
525500
526501
np.random.seed(123456)
527-
plt.figure()
528502
529503
.. ipython:: python
530504
@@ -539,7 +513,6 @@ To produce an unstacked plot, pass ``stacked=False``. Alpha value is set to 0.5
539513
:suppress:
540514
541515
plt.close('all')
542-
plt.figure()
543516
544517
.. ipython:: python
545518
@@ -560,7 +533,6 @@ These can be specified by the ``x`` and ``y`` keywords.
560533
561534
np.random.seed(123456)
562535
plt.close('all')
563-
plt.figure()
564536
565537
.. ipython:: python
566538
@@ -626,7 +598,6 @@ too dense to plot each point individually.
626598
.. ipython:: python
627599
:suppress:
628600
629-
plt.figure()
630601
np.random.seed(123456)
631602
632603
.. ipython:: python
@@ -654,7 +625,6 @@ given by column ``z``. The bins are aggregated with NumPy's ``max`` function.
654625
:suppress:
655626
656627
plt.close('all')
657-
plt.figure()
658628
np.random.seed(123456)
659629
660630
.. ipython:: python
@@ -688,7 +658,6 @@ A ``ValueError`` will be raised if there are any negative values in your data.
688658
:suppress:
689659
690660
np.random.seed(123456)
691-
plt.figure()
692661
693662
.. ipython:: python
694663
@@ -718,7 +687,6 @@ drawn in each pie plots by default; specify ``legend=False`` to hide it.
718687
:suppress:
719688
720689
np.random.seed(123456)
721-
plt.figure()
722690
723691
.. ipython:: python
724692
@@ -744,12 +712,6 @@ If you want to hide wedge labels, specify ``labels=None``.
744712
If ``fontsize`` is specified, the value will be applied to wedge labels.
745713
Also, other keywords supported by :func:`matplotlib.pyplot.pie` can be used.
746714

747-
748-
.. ipython:: python
749-
:suppress:
750-
751-
plt.figure()
752-
753715
.. ipython:: python
754716
755717
@savefig series_pie_plot_options.png
@@ -762,7 +724,6 @@ If you pass values whose sum total is less than 1.0, matplotlib draws a semicirc
762724
:suppress:
763725
764726
plt.close('all')
765-
plt.figure()
766727
767728
.. ipython:: python
768729
@@ -860,7 +821,6 @@ You can create density plots using the :meth:`Series.plot.kde` and :meth:`DataFr
860821
.. ipython:: python
861822
:suppress:
862823
863-
plt.figure()
864824
np.random.seed(123456)
865825
866826
.. ipython:: python
@@ -895,8 +855,6 @@ of the same class will usually be closer together and form larger structures.
895855
896856
data = pd.read_csv('data/iris.data')
897857
898-
plt.figure()
899-
900858
@savefig andrews_curves.png
901859
andrews_curves(data, 'Name')
902860
@@ -919,8 +877,6 @@ represents one data point. Points that tend to cluster will appear closer togeth
919877
920878
data = pd.read_csv('data/iris.data')
921879
922-
plt.figure()
923-
924880
@savefig parallel_coordinates.png
925881
parallel_coordinates(data, 'Name')
926882
@@ -949,8 +905,6 @@ be passed, and when ``lag=1`` the plot is essentially ``data[:-1]`` vs.
949905
950906
from pandas.plotting import lag_plot
951907
952-
plt.figure()
953-
954908
spacing = np.linspace(-99 * np.pi, 99 * np.pi, num=1000)
955909
data = pd.Series(0.1 * np.random.rand(1000) + 0.9 * np.sin(spacing))
956910
@@ -986,8 +940,6 @@ autocorrelation plots.
986940
987941
from pandas.plotting import autocorrelation_plot
988942
989-
plt.figure()
990-
991943
spacing = np.linspace(-9 * np.pi, 9 * np.pi, num=1000)
992944
data = pd.Series(0.7 * np.random.rand(1000) + 0.3 * np.sin(spacing))
993945
@@ -1055,8 +1007,6 @@ for more information.
10551007
10561008
data = pd.read_csv('data/iris.data')
10571009
1058-
plt.figure()
1059-
10601010
@savefig radviz.png
10611011
radviz(data, 'Name')
10621012
@@ -1091,7 +1041,7 @@ layout and formatting of the returned plot:
10911041
.. ipython:: python
10921042
10931043
@savefig series_plot_basic2.png
1094-
plt.figure(); ts.plot(style='k--', label='Series')
1044+
ts.plot(style='k--', label='Series')
10951045
10961046
.. ipython:: python
10971047
:suppress:
@@ -1138,7 +1088,6 @@ You may pass ``logy`` to get a log-scale Y axis.
11381088
.. ipython:: python
11391089
:suppress:
11401090
1141-
plt.figure()
11421091
np.random.seed(123456)
11431092
11441093
.. ipython:: python
@@ -1162,11 +1111,6 @@ Plotting on a Secondary Y-axis
11621111

11631112
To plot data on a secondary y-axis, use the ``secondary_y`` keyword:
11641113

1165-
.. ipython:: python
1166-
:suppress:
1167-
1168-
plt.figure()
1169-
11701114
.. ipython:: python
11711115
11721116
df.A.plot()
@@ -1184,7 +1128,6 @@ keyword:
11841128

11851129
.. ipython:: python
11861130
1187-
plt.figure()
11881131
ax = df.plot(secondary_y=['A', 'B'])
11891132
ax.set_ylabel('CD scale')
11901133
@savefig frame_plot_secondary_y.png
@@ -1201,8 +1144,6 @@ with "(right)" in the legend. To turn off the automatic marking, use the
12011144

12021145
.. ipython:: python
12031146
1204-
plt.figure()
1205-
12061147
@savefig frame_plot_secondary_y_no_right.png
12071148
df.plot(secondary_y=['A', 'B'], mark_right=False)
12081149
@@ -1223,8 +1164,6 @@ Here is the default behavior, notice how the x-axis tick labeling is performed:
12231164

12241165
.. ipython:: python
12251166
1226-
plt.figure()
1227-
12281167
@savefig ser_plot_suppress.png
12291168
df.A.plot()
12301169
@@ -1237,8 +1176,6 @@ Using the ``x_compat`` parameter, you can suppress this behavior:
12371176

12381177
.. ipython:: python
12391178
1240-
plt.figure()
1241-
12421179
@savefig ser_plot_suppress_parm.png
12431180
df.A.plot(x_compat=True)
12441181
@@ -1252,8 +1189,6 @@ in ``pandas.plotting.plot_params`` can be used in a `with statement`:
12521189

12531190
.. ipython:: python
12541191
1255-
plt.figure()
1256-
12571192
@savefig ser_plot_suppress_context.png
12581193
with pd.plotting.plot_params.use('x_compat', True):
12591194
df.A.plot(color='r')
@@ -1531,8 +1466,6 @@ To use the cubehelix colormap, we can pass ``colormap='cubehelix'``.
15311466
df = pd.DataFrame(np.random.randn(1000, 10), index=ts.index)
15321467
df = df.cumsum()
15331468
1534-
plt.figure()
1535-
15361469
@savefig cubehelix.png
15371470
df.plot(colormap='cubehelix')
15381471
@@ -1547,8 +1480,6 @@ Alternatively, we can pass the colormap itself:
15471480
15481481
from matplotlib import cm
15491482
1550-
plt.figure()
1551-
15521483
@savefig cubehelix_cm.png
15531484
df.plot(colormap=cm.cubehelix)
15541485
@@ -1569,8 +1500,6 @@ Colormaps can also be used other plot types, like bar charts:
15691500
dd = pd.DataFrame(np.random.randn(10, 10)).applymap(abs)
15701501
dd = dd.cumsum()
15711502
1572-
plt.figure()
1573-
15741503
@savefig greens.png
15751504
dd.plot.bar(colormap='Greens')
15761505
@@ -1583,8 +1512,6 @@ Parallel coordinates charts:
15831512

15841513
.. ipython:: python
15851514
1586-
plt.figure()
1587-
15881515
@savefig parallel_gist_rainbow.png
15891516
parallel_coordinates(data, 'Name', colormap='gist_rainbow')
15901517
@@ -1597,8 +1524,6 @@ Andrews curves charts:
15971524

15981525
.. ipython:: python
15991526
1600-
plt.figure()
1601-
16021527
@savefig andrews_curve_winter.png
16031528
andrews_curves(data, 'Name', colormap='winter')
16041529
@@ -1634,8 +1559,6 @@ when plotting a large number of points.
16341559
ma = price.rolling(20).mean()
16351560
mstd = price.rolling(20).std()
16361561
1637-
plt.figure()
1638-
16391562
plt.plot(price.index, price, 'k')
16401563
plt.plot(ma.index, ma, 'b')
16411564
@savefig bollinger.png

0 commit comments

Comments
 (0)