From f85ab1b38c80e9d55c52bb2ad8162aca545da59d Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 6 Feb 2018 01:25:06 -0500 Subject: [PATCH 1/3] Remove demo_new_colorbar example. The normal colorbar works fine if calling colorbar.set_ticks instead of colobar.ax.set_ticks, which is noted in the deprecation warning. There is no real benefit of showing the axes_grid1 version now. --- examples/axes_grid1/demo_new_colorbar.py | 25 ------------------------ 1 file changed, 25 deletions(-) delete mode 100644 examples/axes_grid1/demo_new_colorbar.py diff --git a/examples/axes_grid1/demo_new_colorbar.py b/examples/axes_grid1/demo_new_colorbar.py deleted file mode 100644 index 92b6a4fda555..000000000000 --- a/examples/axes_grid1/demo_new_colorbar.py +++ /dev/null @@ -1,25 +0,0 @@ -""" -================= -Demo New Colorbar -================= - -""" -import matplotlib.pyplot as plt -from mpl_toolkits.axes_grid1.colorbar import colorbar - - -plt.rcParams["text.usetex"] = False - -fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(6, 3)) - -im1 = ax1.imshow([[1, 2], [3, 4]]) -cb1 = fig.colorbar(im1, ax=ax1) -cb1.ax.set_yticks([1, 3]) -ax1.set_title("Original MPL's colorbar w/\nset_yticks([1,3])", size=10) - -im2 = ax2.imshow([[1, 2], [3, 4]]) -cb2 = colorbar(im2, ax=ax2) -cb2.ax.set_yticks([1, 3]) -ax2.set_title("AxesGrid's colorbar w/\nset_yticks([1,3])", size=10) - -plt.show() From 14b3ec0eee95d8ee3beadec0495c52b8b21b1d70 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 6 Feb 2018 01:26:44 -0500 Subject: [PATCH 2/3] Avoid csv2rec warning in plotfile. Unfortunately, csv2rec provides some automatic converters, so it can't be replaced entirely with np.genfromtxt or np.loadtxt. --- lib/matplotlib/pyplot.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/pyplot.py b/lib/matplotlib/pyplot.py index b07c354adef4..296a05bede20 100644 --- a/lib/matplotlib/pyplot.py +++ b/lib/matplotlib/pyplot.py @@ -2411,8 +2411,11 @@ def plotfile(fname, cols=(0,), plotfuncs=None, if plotfuncs is None: plotfuncs = dict() - r = mlab.csv2rec(fname, comments=comments, skiprows=skiprows, - checkrows=checkrows, delimiter=delimiter, names=names) + from matplotlib.cbook import mplDeprecation + with warnings.catch_warnings(): + warnings.simplefilter('ignore', mplDeprecation) + r = mlab.csv2rec(fname, comments=comments, skiprows=skiprows, + checkrows=checkrows, delimiter=delimiter, names=names) def getname_val(identifier): 'return the name and column data for identifier' From 519392294bfdcb3a2642936fd6100a8677de0131 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 6 Feb 2018 01:51:55 -0500 Subject: [PATCH 3/3] Avoid deprecations in examples. --- .../make_room_for_ylabel_using_axesgrid.py | 2 +- .../image_transparency_blend.py | 3 ++- examples/showcase/bachelors_degrees_by_gender.py | 16 +++++++++------- examples/statistics/hist.py | 2 +- .../subplots_axes_and_figures/broken_axis.py | 2 +- .../ticks_and_spines/date_index_formatter.py | 14 +++++++++----- tutorials/introductory/pyplot.py | 2 +- 7 files changed, 24 insertions(+), 17 deletions(-) diff --git a/examples/axes_grid1/make_room_for_ylabel_using_axesgrid.py b/examples/axes_grid1/make_room_for_ylabel_using_axesgrid.py index 48f4bdca834f..28424264ba67 100644 --- a/examples/axes_grid1/make_room_for_ylabel_using_axesgrid.py +++ b/examples/axes_grid1/make_room_for_ylabel_using_axesgrid.py @@ -44,7 +44,7 @@ def ex3(): divider = make_axes_locatable(ax1) ax2 = divider.new_horizontal("100%", pad=0.3, sharey=ax1) - ax2.tick_params(labelleft="off") + ax2.tick_params(labelleft=False) fig.add_axes(ax2) divider.add_auto_adjustable_area(use_axes=[ax1], pad=0.1, diff --git a/examples/images_contours_and_fields/image_transparency_blend.py b/examples/images_contours_and_fields/image_transparency_blend.py index 54a4a59c6923..0f9ce59506aa 100644 --- a/examples/images_contours_and_fields/image_transparency_blend.py +++ b/examples/images_contours_and_fields/image_transparency_blend.py @@ -48,7 +48,8 @@ def normal_pdf(x, mean, var): weights = weights_high + weights_low # We'll also create a grey background into which the pixels will fade -greys = np.ones(weights.shape + (3,)) * 70 +greys = np.empty(weights.shape + (3,), dtype=np.uint8) +greys.fill(70) # First we'll plot these blobs using only ``imshow``. vmax = np.abs(weights).max() diff --git a/examples/showcase/bachelors_degrees_by_gender.py b/examples/showcase/bachelors_degrees_by_gender.py index 1305770f584f..d3c124bc6d67 100644 --- a/examples/showcase/bachelors_degrees_by_gender.py +++ b/examples/showcase/bachelors_degrees_by_gender.py @@ -10,12 +10,14 @@ as an alternative to a conventional legend. """ +import numpy as np import matplotlib.pyplot as plt -from matplotlib.mlab import csv2rec from matplotlib.cbook import get_sample_data -with get_sample_data('percent_bachelors_degrees_women_usa.csv') as fname: - gender_degree_data = csv2rec(fname) + +fname = get_sample_data('percent_bachelors_degrees_women_usa.csv', + asfileobj=False) +gender_degree_data = np.genfromtxt(fname, delimiter=',', names=True) # These are the colors that will be used in the plot color_sequence = ['#1f77b4', '#aec7e8', '#ff7f0e', '#ffbb78', '#2ca02c', @@ -59,8 +61,8 @@ # Remove the tick marks; they are unnecessary with the tick lines we just # plotted. -plt.tick_params(axis='both', which='both', bottom='off', top='off', - labelbottom='on', left='off', right='off', labelleft='on') +plt.tick_params(axis='both', which='both', bottom=False, top=False, + labelbottom=True, left=False, right=False, labelleft=True) # Now that the plot is prepared, it's time to actually plot the data! # Note that I plotted the majors in order of the highest % in the final year. @@ -80,9 +82,9 @@ for rank, column in enumerate(majors): # Plot each line separately with its own color. - column_rec_name = column.replace('\n', '_').replace(' ', '_').lower() + column_rec_name = column.replace('\n', '_').replace(' ', '_') - line = plt.plot(gender_degree_data.year, + line = plt.plot(gender_degree_data['Year'], gender_degree_data[column_rec_name], lw=2.5, color=color_sequence[rank]) diff --git a/examples/statistics/hist.py b/examples/statistics/hist.py index fa55549f901d..b5ff5ad0034b 100644 --- a/examples/statistics/hist.py +++ b/examples/statistics/hist.py @@ -63,7 +63,7 @@ thispatch.set_facecolor(color) # We can also normalize our inputs by the total number of counts -axs[1].hist(x, bins=n_bins, normed=True) +axs[1].hist(x, bins=n_bins, density=True) # Now we format the y-axis to display percentage axs[1].yaxis.set_major_formatter(PercentFormatter(xmax=1)) diff --git a/examples/subplots_axes_and_figures/broken_axis.py b/examples/subplots_axes_and_figures/broken_axis.py index f6c2a1fb9959..613955378798 100644 --- a/examples/subplots_axes_and_figures/broken_axis.py +++ b/examples/subplots_axes_and_figures/broken_axis.py @@ -36,7 +36,7 @@ ax.spines['bottom'].set_visible(False) ax2.spines['top'].set_visible(False) ax.xaxis.tick_top() -ax.tick_params(labeltop='off') # don't put tick labels at the top +ax.tick_params(labeltop=False) # don't put tick labels at the top ax2.xaxis.tick_bottom() # This looks pretty good, and was fairly painless, but you can get that diff --git a/examples/ticks_and_spines/date_index_formatter.py b/examples/ticks_and_spines/date_index_formatter.py index 8a75f369e836..5d3688583a3b 100644 --- a/examples/ticks_and_spines/date_index_formatter.py +++ b/examples/ticks_and_spines/date_index_formatter.py @@ -12,15 +12,19 @@ """ from __future__ import print_function + import numpy as np -from matplotlib.mlab import csv2rec + import matplotlib.pyplot as plt import matplotlib.cbook as cbook +from matplotlib.dates import bytespdate2num, num2date from matplotlib.ticker import Formatter + datafile = cbook.get_sample_data('msft.csv', asfileobj=False) print('loading %s' % datafile) -r = csv2rec(datafile)[-40:] +msft_data = np.genfromtxt(datafile, delimiter=',', names=True, + converters={0: bytespdate2num('%d-%b-%y')})[-40:] class MyFormatter(Formatter): @@ -34,12 +38,12 @@ def __call__(self, x, pos=0): if ind >= len(self.dates) or ind < 0: return '' - return self.dates[ind].strftime(self.fmt) + return num2date(self.dates[ind]).strftime(self.fmt) -formatter = MyFormatter(r.date) +formatter = MyFormatter(msft_data['Date']) fig, ax = plt.subplots() ax.xaxis.set_major_formatter(formatter) -ax.plot(np.arange(len(r)), r.close, 'o-') +ax.plot(np.arange(len(msft_data)), msft_data['Close'], 'o-') fig.autofmt_xdate() plt.show() diff --git a/tutorials/introductory/pyplot.py b/tutorials/introductory/pyplot.py index f2bc82e7beb4..92fc3a3dfdf6 100644 --- a/tutorials/introductory/pyplot.py +++ b/tutorials/introductory/pyplot.py @@ -333,7 +333,7 @@ def f(t): x = mu + sigma * np.random.randn(10000) # the histogram of the data -n, bins, patches = plt.hist(x, 50, normed=1, facecolor='g', alpha=0.75) +n, bins, patches = plt.hist(x, 50, density=1, facecolor='g', alpha=0.75) plt.xlabel('Smarts')