Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b1141fd

Browse files
committed
Deprecate plotfile.
Various replacements are showcased in plotfile_demo_sgskip.
1 parent 699f35e commit b1141fd

File tree

5 files changed

+97
-46
lines changed

5 files changed

+97
-46
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Deprecations
2+
````````````
3+
4+
`.pyplot.plotfile` is deprecated in favor of separately loading and plotting
5+
the data. See :doc:`/gallery/misc/plotfile_demo_sgskip` for various ways to
6+
use pandas or numpy to load data, and pandas or matplotlib to plot the
7+
resulting data.

examples/misc/plotfile_demo.py

Lines changed: 0 additions & 45 deletions
This file was deleted.

examples/misc/plotfile_demo_sgskip.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
"""
2+
=============
3+
plotfile demo
4+
=============
5+
6+
Replacing the deprecated `plotfile` by pandas or other matplotlib plotting
7+
methods.
8+
"""
9+
10+
import matplotlib.pyplot as plt
11+
import matplotlib.cbook as cbook
12+
13+
import numpy as np
14+
import pandas as pd
15+
pd.plotting.register_matplotlib_converters()
16+
17+
# Time series.
18+
fname = cbook.get_sample_data('msft.csv', asfileobj=False)
19+
with cbook.get_sample_data('msft.csv') as file:
20+
msft = pd.read_csv(file, parse_dates=['Date'])
21+
22+
# Use indices.
23+
plt.plotfile(fname, (0, 5, 6))
24+
25+
msft.plot(0, [5, 6], subplots=True)
26+
27+
# Use names.
28+
plt.plotfile(fname, ('date', 'volume', 'adj_close'))
29+
30+
msft.plot("Date", ["Volume", "Adj. Close*"], subplots=True)
31+
32+
# Use semilogy for volume.
33+
plt.plotfile(fname, ('date', 'volume', 'adj_close'),
34+
plotfuncs={'volume': 'semilogy'})
35+
36+
fig, axs = plt.subplots(2, sharex=True)
37+
msft.plot("Date", "Volume", ax=axs[0], logy=True)
38+
msft.plot("Date", "Adj. Close*", ax=axs[1])
39+
40+
# Use semilogy for volume (by index).
41+
plt.plotfile(fname, (0, 5, 6), plotfuncs={5: 'semilogy'})
42+
43+
fig, axs = plt.subplots(2, sharex=True)
44+
msft.plot(0, 5, ax=axs[0], logy=True)
45+
msft.plot(0, 6, ax=axs[1])
46+
47+
# Single subplot
48+
plt.plotfile(fname, ('date', 'open', 'high', 'low', 'close'), subplots=False)
49+
50+
msft.plot("Date", ["Open", "High", "Low", "Close"])
51+
52+
# Use bar for volume
53+
plt.plotfile(fname, (0, 5, 6), plotfuncs={5: "bar"})
54+
55+
fig, axs = plt.subplots(2, sharex=True)
56+
axs[0].bar(msft.iloc[:, 0], msft.iloc[:, 5])
57+
axs[1].plot(msft.iloc[:, 0], msft.iloc[:, 6])
58+
fig.autofmt_xdate()
59+
60+
###############################################################################
61+
62+
# Unlabeled data.
63+
fname2 = cbook.get_sample_data('data_x_x2_x3.csv', asfileobj=False)
64+
with cbook.get_sample_data('data_x_x2_x3.csv') as file:
65+
array = np.loadtxt(file)
66+
67+
# Labeling, if no names in csv-file.
68+
plt.plotfile(fname2, cols=(0, 1, 2), delimiter=' ',
69+
names=['$x$', '$f(x)=x^2$', '$f(x)=x^3$'])
70+
71+
fig, axs = plt.subplots(2, sharex=True)
72+
axs[0].plot(array[:, 0], array[:, 1])
73+
axs[0].set(ylabel='$f(x)=x^2$')
74+
axs[1].plot(array[:, 0], array[:, 2])
75+
axs[1].set(xlabel='$x$', ylabel='$f(x)=x^3$')
76+
77+
# More than one file per figure--illustrated here with a single file.
78+
plt.plotfile(fname2, cols=(0, 1), delimiter=' ')
79+
plt.plotfile(fname2, cols=(0, 2), newfig=False,
80+
delimiter=' ') # use current figure
81+
plt.xlabel(r'$x$')
82+
plt.ylabel(r'$f(x) = x^2, x^3$')
83+
84+
fig, ax = plt.subplots()
85+
ax.plot(array[:, 0], array[:, 1])
86+
ax.plot(array[:, 0], array[:, 2])
87+
ax.set(xlabel='$x$', ylabel='$f(x)=x^3$')
88+
89+
plt.show()

examples/tests/backend_driver_sgskip.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@
212212
'pcolor_log.py',
213213
'pcolor_small.py',
214214
'pie_demo2.py',
215-
'plotfile_demo.py',
216215
'polar_demo.py',
217216
'polar_legend.py',
218217
'psd_demo.py',

lib/matplotlib/pyplot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2176,6 +2176,7 @@ def polar(*args, **kwargs):
21762176
return ret
21772177

21782178

2179+
@cbook.deprecated("3.1")
21792180
def plotfile(fname, cols=(0,), plotfuncs=None,
21802181
comments='#', skiprows=0, checkrows=5, delimiter=',',
21812182
names=None, subplots=True, newfig=True, **kwargs):

0 commit comments

Comments
 (0)