8000 Avoid deprecations in examples. · matplotlib/matplotlib@c4197df · GitHub
[go: up one dir, main page]

Skip to content

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

8000
Appearance settings

Commit c4197df

Browse files
committed
Avoid deprecations in examples.
1 parent 14b3ec0 commit c4197df

File tree

6 files changed

+23
-16
lines changed

6 files changed

+23
-16
lines changed

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+
r = 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(r['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(r)), r['Close'], 'o-')
4448
fig.autofmt_xdate()
4549
plt.show()

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, 477F density=1, facecolor='g', alpha=0.75)
337337

338338

339339
plt.xlabel('Smarts')

0 commit comments

Comments
 (0)
0