## matplotlib-checkins

 SF.net SVN: matplotlib:[8211] trunk/matplotlib/examples/pylab_examples/ demo_agg_filter.py From: - 2010-03-23 17:23:56 ```Revision: 8211 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8211&view=rev Author: leejjoon Date: 2010-03-23 17:23:50 +0000 (Tue, 23 Mar 2010) Log Message: ----------- remove scipy dependency in examples/pylab_examples/demo_agg_filter.py Modified Paths: -------------- trunk/matplotlib/examples/pylab_examples/demo_agg_filter.py Modified: trunk/matplotlib/examples/pylab_examples/demo_agg_filter.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/demo_agg_filter.py 2010-03-22 16:47:27 UTC (rev 8210) +++ trunk/matplotlib/examples/pylab_examples/demo_agg_filter.py 2010-03-23 17:23:50 UTC (rev 8211) @@ -1,11 +1,30 @@ import matplotlib.pyplot as plt import numpy as np -import scipy.ndimage as NI import matplotlib.cm as cm import matplotlib.mlab as mlab +def smooth1d(x, window_len): + # copied from http://www.scipy.org/Cookbook/SignalSmooth + s=np.r_[2*x[0]-x[window_len:1:-1],x,2*x[-1]-x[-1:-window_len:-1]] + w = np.hanning(window_len) + y=np.convolve(w/w.sum(),s,mode='same') + return y[window_len-1:-window_len+1] + +def smooth2d(A, sigma=3): + + window_len = max(int(sigma), 3)*2+1 + A1 = np.array([smooth1d(x, window_len) for x in np.asarray(A)]) + A2 = np.transpose(A1) + A3 = np.array([smooth1d(x, window_len) for x in A2]) + A4 = np.transpose(A3) + + return A4 + + + + class BaseFilter(object): def prepare_image(self, src_image, dpi, pad): ny, nx, depth = src_image.shape @@ -58,8 +77,9 @@ def process_image(self, padded_src, dpi): #offsetx, offsety = int(self.offsets[0]), int(self.offsets[1]) tgt_image = np.zeros_like(padded_src) - tgt_image[:,:,-1] = NI.gaussian_filter(padded_src[:,:,-1]*self.alpha, - self.sigma) + aa = smooth2d(padded_src[:,:,-1]*self.alpha, + self.sigma) + tgt_image[:,:,-1] = aa tgt_image[:,:,:-1] = self.color return tgt_image @@ -123,7 +143,7 @@ alpha = new_im[:,:,3] alpha.fill(0) alpha[pad:-pad, pad:-pad] = im[:,:,-1] - alpha2 = NI.grey_dilation(alpha, size=(self.pixels, self.pixels)) + alpha2 = np.clip(smooth2d(alpha, self.pixels) * 5, 0, 1) new_im[:,:,-1] = alpha2 new_im[:,:,:-1] = self.color offsetx, offsety = -pad, -pad @@ -208,7 +228,7 @@ mec="r", mfc="w", lw=5, mew=3, ms=10, label="Line 1") - gauss = DropShadowFilter(2) + gauss = DropShadowFilter(4) for l in [l1, l2]: @@ -257,7 +277,7 @@ rects2 = ax.bar(ind+width+0.1, womenMeans, width, color='y', ec="w", lw=2) #gauss = GaussianFilter(1.5, offsets=(1,1), ) - gauss = DropShadowFilter(1.5, offsets=(1,1), ) + gauss = DropShadowFilter(5, offsets=(1,1), ) shadow = FilteredArtistList(rects1+rects2, gauss) ax.add_artist(shadow) shadow.set_zorder(rects1[0].get_zorder()-0.1) @@ -275,21 +295,21 @@ pies = ax.pie(fracs, explode=explode) ax.patch.set_visible(True) - light_filter = LightFilter(8) + light_filter = LightFilter(9) for p in pies[0]: p.set_agg_filter(light_filter) p.set_rasterized(True) # to support mixed-mode renderers p.set(ec="none", lw=2) - gauss = DropShadowFilter(3, offsets=(3,4), alpha=0.7) + gauss = DropShadowFilter(9, offsets=(3,4), alpha=0.7) shadow = FilteredArtistList(pies[0], gauss) ax.add_artist(shadow) shadow.set_zorder(pies[0][0].get_zorder()-0.1) if 1: - + plt.figure(1, figsize=(6, 6)) plt.subplots_adjust(left=0.05, right=0.95) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 SF.net SVN: matplotlib:[8212] trunk/matplotlib/examples/pylab_examples/ demo_agg_filter.py From: - 2010-03-23 17:38:02 ```Revision: 8212 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8212&view=rev Author: leejjoon Date: 2010-03-23 17:37:51 +0000 (Tue, 23 Mar 2010) Log Message: ----------- make filters dpi-independent in examples/pylab_examples/demo_agg_filter.py Modified Paths: -------------- trunk/matplotlib/examples/pylab_examples/demo_agg_filter.py Modified: trunk/matplotlib/examples/pylab_examples/demo_agg_filter.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/demo_agg_filter.py 2010-03-23 17:23:50 UTC (rev 8211) +++ trunk/matplotlib/examples/pylab_examples/demo_agg_filter.py 2010-03-23 17:37:51 UTC (rev 8212) @@ -52,12 +52,12 @@ self.offsets = offsets def get_pad(self, dpi): - return max(*self.offsets) + return int(max(*self.offsets)/72.*dpi) def process_image(self, padded_src, dpi): ox, oy = self.offsets - a1 = np.roll(padded_src, ox, axis=1) - a2 = np.roll(a1, -oy, axis=0) + a1 = np.roll(padded_src, int(ox/72.*dpi), axis=1) + a2 = np.roll(a1, -int(oy/72.*dpi), axis=0) return a2 class GaussianFilter(BaseFilter): @@ -71,14 +71,14 @@ self.color=color def get_pad(self, dpi): - return int(self.sigma*3) + return int(self.sigma*3/72.*dpi) def process_image(self, padded_src, dpi): #offsetx, offsety = int(self.offsets[0]), int(self.offsets[1]) tgt_image = np.zeros_like(padded_src) aa = smooth2d(padded_src[:,:,-1]*self.alpha, - self.sigma) + self.sigma/72.*dpi) tgt_image[:,:,-1] = aa tgt_image[:,:,:-1] = self.color return tgt_image @@ -143,7 +143,7 @@ alpha = new_im[:,:,3] alpha.fill(0) alpha[pad:-pad, pad:-pad] = im[:,:,-1] - alpha2 = np.clip(smooth2d(alpha, self.pixels) * 5, 0, 1) + alpha2 = np.clip(smooth2d(alpha, self.pixels/72.*dpi) * 5, 0, 1) new_im[:,:,-1] = alpha2 new_im[:,:,:-1] = self.color offsetx, offsety = -pad, -pad @@ -206,8 +206,10 @@ fontsize=11) # change clable color to black + from matplotlib.patheffects import Normal for t in cl: t.set_color("k") + t.set_path_effects([Normal()]) # to force TextPath (i.e., same font in all backends) # Add white glows to improve visibility of labels. white_glows = FilteredArtistList(cl, GrowFilter(3)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```