8000 Merge pull request #10385 from QuLogic/example-deprecations · matplotlib/matplotlib@83d614b · GitHub
[go: up one dir, main page]

Skip to content

Commit 83d614b

Browse files
authored
Merge pull request #10385 from QuLogic/example-deprecations
DOC: Fix deprecations in examples
2 parents 47b6ab0 + 5193922 commit 83d614b

File tree

9 files changed

+29
-44
lines changed

9 files changed

+29
-44
lines changed

examples/axes_grid1/demo_new_colorbar.py

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

examples/axes_grid1/make_room_for_ylabel_using_axesgrid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def ex3():
4444
divider = make_axes_locatable(ax1)
4545

4646
ax2 = divider.new_horizontal("100%", pad=0.3, sharey=ax1)
47-
ax2.tick_params(labelleft="off")
47+
ax2.tick_params(labelleft=False)
4848
fig.add_axes(ax2)
4949

5050
divider.add_auto_adjustable_area(use_axes=[ax1], pad=0.1,

examples/images_contours_and_fields/image_transparency_blend.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ def normal_pdf(x, mean, var):
4848
weights = weights_high + weights_low
4949

5050
# We'll also create a grey background into which the pixels will fade
51-
greys = np.ones(weights.shape + (3,)) * 70
51+
greys = np.empty(weights.shape + (3,), dtype=np.uint8)
52+
greys.fill(70)
5253

5354
# First we'll plot these blobs using only ``imshow``.
5455
vmax = np.abs(weights).max()

examples/showcase/bachelors_degrees_by_gender.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
as an alternative to a conventional legend.
1111
"""
1212

13+
import numpy as np
1314
import matplotlib.pyplot as plt
14-
from matplotlib.mlab import csv2rec
1515
from matplotlib.cbook import get_sample_data
1616

17-
with get_sample_data('percent_bachelors_degrees_women_usa.csv') as fname:
18-
gender_degree_data = csv2rec(fname)
17+
18+
fname = get_sample_data('percent_bachelors_degrees_women_usa.csv',
19+
asfileobj=False)
20+
gender_degree_data = np.genfromtxt(fname, delimiter=',', names=True)
1921

2022
# These are the colors that will be used in the plot
2123
color_sequence = ['#1f77b4', '#aec7e8', '#ff7f0e', '#ffbb78', '#2ca02c',
@@ -59,8 +61,8 @@
5961

6062
# Remove the tick marks; they are unnecessary with the tick lines we just
6163
# plotted.
62-
plt.tick_params(axis='both', which='both', bottom='off', top='off',
63-
labelbottom='on', left='off', right='off', labelleft='on')
64+
plt.tick_params(axis='both', which='both', bottom=False, top=False,
65+
labelbottom=True, left=False, right=False, labelleft=True)
6466

6567
# Now that the plot is prepared, it's time to actually plot the data!
6668
# Note that I plotted the majors in order of the highest % in the final year.
@@ -80,9 +82,9 @@
8082

8183
for rank, column in enumerate(majors):
8284
# Plot each line separately with its own color.
83-
column_rec_name = column.replace('\n', '_').replace(' ', '_').lower()
85+
column_rec_name = column.replace('\n', '_').replace(' ', '_')
8486

85-
line = plt.plot(gender_degree_data.year,
87+
line = plt.plot(gender_degree_data['Year'],
8688
gender_degree_data[column_rec_name],
8789
lw=2.5,
8890
color=color_sequence[rank])

examples/statistics/hist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
thispatch.set_facecolor(color)
6464

6565
# We can also normalize our inputs by the total number of counts
66-
axs[1].hist(x, bins=n_bins, normed=True)
66+
axs[1].hist(x, bins=n_bins, density=True)
6767

6868
# Now we format the y-axis to display percentage
6969
axs[1].yaxis.set_major_formatter(PercentFormatter(xmax=1))

examples/subplots_axes_and_figures/broken_axis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
ax.spines['bottom'].set_visible(False)
3737
ax2.spines['top'].set_visible(False)
3838
ax.xaxis.tick_top()
39-
ax.tick_params(labeltop='off') # don't put tick labels at the top
39+
ax.tick_params(labeltop=False) # don't put tick labels at the top
4040
ax2.xaxis.tick_bottom()
4141

4242
# This looks pretty good, and was fairly painless, but you can get that

examples/ticks_and_spines/date_index_formatter.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@
1212
"""
1313

1414
from __future__ import print_function
15+
1516
import numpy as np
16-
from matplotlib.mlab import csv2rec
17+
1718
import matplotlib.pyplot as plt
1819
import matplotlib.cbook as cbook
20+
from matplotlib.dates import bytespdate2num, num2date
1921
from matplotlib.ticker import Formatter
2022

23+
2124
datafile = cbook.get_sample_data('msft.csv', asfileobj=False)
2225
print('loading %s' % datafile)
23-
r = csv2rec(datafile)[-40:]
26+
msft_data = np.genfromtxt(datafile, delimiter=',', names=True,
27+
converters={0: bytespdate2num('%d-%b-%y')})[-40:]
2428

2529

2630
class MyFormatter(Formatter):
@@ -34,12 +38,12 @@ def __call__(self, x, pos=0):
3438
if ind >= len(self.dates) or ind < 0:
3539
return ''
3640

37-
return self.dates[ind].strftime(self.fmt)
41+
return num2date(self.dates[ind]).strftime(self.fmt)
3842

39-
formatter = MyFormatter(r.date)
43+
formatter = MyFormatter(msft_data['Date'])
4044

4145
fig, ax = plt.subplots()
4246
ax.xaxis.set_major_formatter(formatter)
43-
ax.plot(np.arange(len(r)), r.close, 'o-')
47+
ax.plot(np.arange(len(msft_data)), msft_data['Close'], 'o-')
4448
fig.autofmt_xdate()
4549
plt.show()

lib/matplotlib/pyplot.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2411,8 +2411,11 @@ def plotfile(fname, cols=(0,), plotfuncs=None,
24112411

24122412
if plotfuncs is None:
24132413
plotfuncs = dict()
2414-
r = mlab.csv2rec(fname, comments=comments, skiprows=skiprows,
2415-
checkrows=checkrows, delimiter=delimiter, names=names)
2414+
from matplotlib.cbook import mplDeprecation
2415+
with warnings.catch_warnings():
2416+
warnings.simplefilter('ignore', mplDeprecation)
2417+
r = mlab.csv2rec(fname, comments=comments, skiprows=skiprows,
2418+
checkrows=checkrows, delimiter=delimiter, names=names)
24162419

24172420
def getname_val(identifier):
24182421
'return the name and column data for identifier'

tutorials/introductory/pyplot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def f(t):
333333
x = mu + sigma * np.random.randn(10000)
334334

335335
# the histogram of the data
336-
n, bins, patches = plt.hist(x, 50, normed=1, facecolor='g', alpha=0.75)
336+
n, bins, patches = plt.hist(x, 50, density=1, facecolor='g', alpha=0.75)
337337

338338

339339
plt.xlabel('Smarts')

0 commit comments

Comments
 (0)
0