| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
26 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,21 +1,19 @@ | |||
| 1 | - from pylab import * | ||
| 2 | 1 | import numpy as np | |
| 2 | + import matplotlib.pyplot as plt | ||
| 3 | 3 | from matplotlib.transforms import Bbox | |
| 4 | 4 | from matplotlib.path import Path | |
| 5 | - from matplotlib.patches import Rectangle | ||
| 6 | 5 | ||
| 7 | - rect = Rectangle((-1, -1), 2, 2, facecolor="#aaaaaa") | ||
| 8 | - gca().add_patch(rect) | ||
| 6 | + rect = plt.Rectangle((-1, -1), 2, 2, facecolor="#aaaaaa") | ||
| 7 | + plt.gca().add_patch(rect) | ||
| 9 | 8 | bbox = Bbox.from_bounds(-1, -1, 2, 2) | |
| 10 | 9 | ||
| 11 | 10 | for i in range(12): | |
| 12 | - vertices = (np.random.random((4, 2)) - 0.5) * 6.0 | ||
| 13 | - vertices = np.ma.masked_array(vertices, [[False, False], [True, True], [False, False], [False, False]]) | ||
| 11 | + vertices = (np.random.random((2, 2)) - 0.5) * 6.0 | ||
| 14 | 12 | path = Path(vertices) | |
| 15 | 13 | if path.intersects_bbox(bbox): | |
| 16 | 14 | color = 'r' | |
| 17 | 15 | else: | |
| 18 | 16 | color = 'b' | |
| 19 | - plot(vertices[:,0], vertices[:,1], color=color) | ||
| 17 | + plt.plot(vertices[:,0], vertices[:,1], color=color) | ||
| 20 | 18 | ||
| 21 | - show() | ||
| 19 | + plt.show() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,6 @@ | |||
| 3 | 3 | """ | |
| 4 | 4 | import numpy as np | |
| 5 | 5 | import matplotlib.pyplot as plt | |
| 6 | - import matplotlib.path as path | ||
| 7 | 6 | import matplotlib.patches as patches | |
| 8 | 7 | ||
| 9 | 8 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,31 +17,31 @@ | |||
| 17 | 17 | ||
| 18 | 18 | ''' | |
| 19 | 19 | ||
| 20 | - import matplotlib.pyplot as P | ||
| 21 | - from matplotlib import collections, axes, transforms | ||
| 20 | + import matplotlib.pyplot as plt | ||
| 21 | + from matplotlib import collections, transforms | ||
| 22 | 22 | from matplotlib.colors import colorConverter | |
| 23 | - import numpy as N | ||
| 23 | + import numpy as np | ||
| 24 | 24 | ||
| 25 | 25 | nverts = 50 | |
| 26 | 26 | npts = 100 | |
| 27 | 27 | ||
| 28 | 28 | # Make some spirals | |
| 29 | - r = N.array(range(nverts)) | ||
| 30 | - theta = N.array(range(nverts)) * (2*N.pi)/(nverts-1) | ||
| 31 | - xx = r * N.sin(theta) | ||
| 32 | - yy = r * N.cos(theta) | ||
| 29 | + r = np.array(range(nverts)) | ||
| 30 | + theta = np.array(range(nverts)) * (2*np.pi)/(nverts-1) | ||
| 31 | + xx = r * np.sin(theta) | ||
| 32 | + yy = r * np.cos(theta) | ||
| 33 | 33 | spiral = list(zip(xx,yy)) | |
| 34 | 34 | ||
| 35 | 35 | # Make some offsets | |
| 36 | - rs = N.random.RandomState([12345678]) | ||
| 36 | + rs = np.random.RandomState([12345678]) | ||
| 37 | 37 | xo = rs.randn(npts) | |
| 38 | 38 | yo = rs.randn(npts) | |
| 39 | 39 | xyo = list(zip(xo, yo)) | |
| 40 | 40 | ||
| 41 | 41 | # Make a list of colors cycling through the rgbcmyk series. | |
| 42 | 42 | colors = [colorConverter.to_rgba(c) for c in ('r','g','b','c','y','m','k')] | |
| 43 | 43 | ||
| 44 | - fig = P.figure() | ||
| 44 | + fig = plt.figure() | ||
| 45 | 45 | ||
| 46 | 46 | a = fig.add_subplot(2,2,1) | |
| 47 | 47 | col = collections.LineCollection([spiral], offsets=xyo, | |
@@ -88,7 +88,7 @@ | |||
| 88 | 88 | a = fig.add_subplot(2,2,3) | |
| 89 | 89 | ||
| 90 | 90 | col = collections.RegularPolyCollection(7, | |
| 91 | - sizes = N.fabs(xx)*10.0, offsets=xyo, | ||
| 91 | + sizes = np.fabs(xx)*10.0, offsets=xyo, | ||
| 92 | 92 | transOffset=a.transData) | |
| 93 | 93 | trans = transforms.Affine2D().scale(fig.dpi/72.0) | |
| 94 | 94 | col.set_transform(trans) # the points to pixels transform | |
@@ -108,9 +108,9 @@ | |||
| 108 | 108 | ncurves = 20 | |
| 109 | 109 | offs = (0.1, 0.0) | |
| 110 | 110 | ||
| 111 | - yy = N.linspace(0, 2*N.pi, nverts) | ||
| 112 | - ym = N.amax(yy) | ||
| 113 | - xx = (0.2 + (ym-yy)/ym)**2 * N.cos(yy-0.4) * 0.5 | ||
| 111 | + yy = np.linspace(0, 2*np.pi, nverts) | ||
| 112 | + ym = np.amax(yy) | ||
| 113 | + xx = (0.2 + (ym-yy)/ym)**2 * np.cos(yy-0.4) * 0.5 | ||
| 114 | 114 | segs = [] | |
| 115 | 115 | for i in range(ncurves): | |
| 116 | 116 | xxx = xx + 0.02*rs.randn(nverts) | |
@@ -128,6 +128,6 @@ | |||
| 128 | 128 | a.set_ylim(a.get_ylim()[::-1]) | |
| 129 | 129 | ||
| 130 | 130 | ||
| 131 | - P.show() | ||
| 131 | + plt.show() | ||
| 132 | 132 | ||
| 133 | 133 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,11 +1,10 @@ | |||
| 1 | 1 | from __future__ import unicode_literals | |
| 2 | + | ||
| 2 | 3 | from matplotlib.axes import Axes | |
| 3 | - from matplotlib import cbook | ||
| 4 | 4 | from matplotlib.patches import Circle | |
| 5 | 5 | from matplotlib.path import Path | |
| 6 | - from matplotlib.ticker import Formatter, Locator, NullLocator, FixedLocator, NullFormatter | ||
| 7 | - from matplotlib.transforms import Affine2D, Affine2DBase, Bbox, \ | ||
| 8 | - BboxTransformTo, IdentityTransform, Transform, TransformWrapper | ||
| 6 | + from matplotlib.ticker import NullLocator, Formatter, FixedLocator | ||
| 7 | + from matplotlib.transforms import Affine2D, BboxTransformTo, Transform | ||
| 9 | 8 | from matplotlib.projections import register_projection | |
| 10 | 9 | import matplotlib.spines as mspines | |
| 11 | 10 | import matplotlib.axis as maxis | |
@@ -309,7 +308,7 @@ class -- it provides a more convenient interface to set the | |||
| 309 | 308 | # by degrees. | |
| 310 | 309 | number = (360.0 / degrees) + 1 | |
| 311 | 310 | self.xaxis.set_major_locator( | |
| 312 | - FixedLocator( | ||
| 311 | + plt.FixedLocator( | ||
| 313 | 312 | np.linspace(-np.pi, np.pi, number, True)[1:-1])) | |
| 314 | 313 | # Set the formatter to display the tick labels in degrees, | |
| 315 | 314 | # rather than radians. | |
@@ -447,11 +446,12 @@ def inverted(self): | |||
| 447 | 446 | # it. | |
| 448 | 447 | register_projection(HammerAxes) | |
| 449 | 448 | ||
| 450 | - # Now make a simple example using the custom projection. | ||
| 451 | - from pylab import * | ||
| 449 | + if __name__ == '__main__': | ||
| 450 | + import matplotlib.pyplot as plt | ||
| 451 | + # Now make a simple example using the custom projection. | ||
| 452 | + plt.subplot(111, projection="custom_hammer") | ||
| 453 | + p = plt.plot([-1, 1, 1], [-1, -1, 1], "o-") | ||
| 454 | + plt.grid(True) | ||
| 452 | 455 | ||
| 453 | - subplot(111, projection="custom_hammer") | ||
| 454 | - p = plot([-1, 1, 1], [-1, -1, 1], "o-") | ||
| 455 | - grid(True) | ||
| 456 | + plt.show() | ||
| 456 | 457 | ||
| 457 | - show() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,11 @@ | |||
| 1 | 1 | from __future__ import unicode_literals | |
| 2 | + | ||
| 3 | + import numpy as np | ||
| 4 | + from numpy import ma | ||
| 2 | 5 | from matplotlib import scale as mscale | |
| 3 | 6 | from matplotlib import transforms as mtransforms | |
| 7 | + from matplotlib.ticker import Formatter, FixedLocator | ||
| 8 | + | ||
| 4 | 9 | ||
| 5 | 10 | class MercatorLatitudeScale(mscale.ScaleBase): | |
| 6 | 11 | """ | |
@@ -149,18 +154,20 @@ def inverted(self): | |||
| 149 | 154 | # that ``matplotlib`` can find it. | |
| 150 | 155 | mscale.register_scale(MercatorLatitudeScale) | |
| 151 | 156 | ||
| 152 | - from pylab import * | ||
| 153 | - import numpy as np | ||
| 154 | 157 | ||
| 155 | - t = arange(-180.0, 180.0, 0.1) | ||
| 156 | - s = t / 360.0 * np.pi | ||
| 158 | + if __name__ == '__main__': | ||
| 159 | + import matplotlib.pyplot as plt | ||
| 160 | + | ||
| 161 | + t = np.arange(-180.0, 180.0, 0.1) | ||
| 162 | + s = t / 360.0 * np.pi | ||
| 163 | + | ||
| 164 | + plt.plot(t, s, '-', lw=2) | ||
| 165 | + plt.gca().set_yscale('mercator') | ||
| 157 | 166 | ||
| 158 | - plot(t, s, '-', lw=2) | ||
| 159 | - gca().set_yscale('mercator') | ||
| 167 | + plt.xlabel('Longitude') | ||
| 168 | + plt.ylabel('Latitude') | ||
| 169 | + plt.title('Mercator: Projection of the Oppressor') | ||
| 170 | + plt.grid(True) | ||
| 160 | 171 | ||
| 161 | - xlabel('Longitude') | ||
| 162 | - ylabel('Latitude') | ||
| 163 | - title('Mercator: Projection of the Oppressor') | ||
| 164 | - grid(True) | ||
| 172 | + plt.show() | ||
| 165 | 173 | ||
| 166 | - show() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,10 +13,8 @@ | |||
| 13 | 13 | """ | |
| 14 | 14 | import datetime | |
| 15 | 15 | import numpy as np | |
| 16 | - import matplotlib | ||
| 17 | 16 | import matplotlib.pyplot as plt | |
| 18 | 17 | import matplotlib.dates as mdates | |
| 19 | - import matplotlib.mlab as mlab | ||
| 20 | 18 | import matplotlib.cbook as cbook | |
| 21 | 19 | ||
| 22 | 20 | years = mdates.YearLocator() # every year | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,8 +6,6 @@ | |||
| 6 | 6 | import matplotlib as mpl | |
| 7 | 7 | import matplotlib.pyplot as plt | |
| 8 | 8 | import matplotlib.cm as cm | |
| 9 | - import matplotlib.mlab as mlab | ||
| 10 | - from pylab import rand | ||
| 11 | 9 | ||
| 12 | 10 | mpl.rcParams['xtick.labelsize'] = 10 | |
| 13 | 11 | mpl.rcParams['ytick.labelsize'] = 12 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,26 +1,28 @@ | |||
| 1 | + import numpy as np | ||
| 1 | 2 | import matplotlib | |
| 2 | 3 | from matplotlib.patches import Circle, Wedge, Polygon | |
| 3 | 4 | from matplotlib.collections import PatchCollection | |
| 4 | - import pylab | ||
| 5 | + import matplotlib.pyplot as plt | ||
| 5 | 6 | ||
| 6 | - fig=pylab.figure() | ||
| 7 | + | ||
| 8 | + fig=plt.figure() | ||
| 7 | 9 | ax=fig.add_subplot(111) | |
| 8 | 10 | ||
| 9 | 11 | resolution = 50 # the number of vertices | |
| 10 | 12 | N = 3 | |
| 11 | - x = pylab.rand(N) | ||
| 12 | - y = pylab.rand(N) | ||
| 13 | - radii = 0.1*pylab.rand(N) | ||
| 13 | + x = np.random.rand(N) | ||
| 14 | + y = np.random.rand(N) | ||
| 15 | + radii = 0.1*np.random.rand(N) | ||
| 14 | 16 | patches = [] | |
| 15 | 17 | for x1,y1,r in zip(x, y, radii): | |
| 16 | 18 | circle = Circle((x1,y1), r) | |
| 17 | 19 | patches.append(circle) | |
| 18 | 20 | ||
| 19 | - x = pylab.rand(N) | ||
| 20 | - y = pylab.rand(N) | ||
| 21 | - radii = 0.1*pylab.rand(N) | ||
| 22 | - theta1 = 360.0*pylab.rand(N) | ||
| 23 | - theta2 = 360.0*pylab.rand(N) | ||
| 21 | + x = np.random.rand(N) | ||
| 22 | + y = np.random.rand(N) | ||
| 23 | + radii = 0.1*np.random.rand(N) | ||
| 24 | + theta1 = 360.0*np.random.rand(N) | ||
| 25 | + theta2 = 360.0*np.random.rand(N) | ||
| 24 | 26 | for x1,y1,r,t1,t2 in zip(x, y, radii, theta1, theta2): | |
| 25 | 27 | wedge = Wedge((x1,y1), r, t1, t2) | |
| 26 | 28 | patches.append(wedge) | |
@@ -34,13 +36,13 @@ | |||
| 34 | 36 | ] | |
| 35 | 37 | ||
| 36 | 38 | for i in range(N): | |
| 37 | - polygon = Polygon(pylab.rand(N,2), True) | ||
| 39 | + polygon = Polygon(np.random.rand(N,2), True) | ||
| 38 | 40 | patches.append(polygon) | |
| 39 | 41 | ||
| 40 | - colors = 100*pylab.rand(len(patches)) | ||
| 42 | + colors = 100*np.random.rand(len(patches)) | ||
| 41 | 43 | p = PatchCollection(patches, cmap=matplotlib.cm.jet, alpha=0.4) | |
| 42 | - p.set_array(pylab.array(colors)) | ||
| 44 | + p.set_array(np.array(colors)) | ||
| 43 | 45 | ax.add_collection(p) | |
| 44 | - pylab.colorbar(p) | ||
| 46 | + plt.colorbar(p) | ||
| 45 | 47 | ||
| 46 | - pylab.show() | ||
| 48 | + plt.show() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,7 @@ | |||
| 5 | 5 | __author__ = "Yannick Copin <ycopin@ipnl.in2p3.fr>" | |
| 6 | 6 | __version__ = "Time-stamp: <10/02/2010 16:49 ycopin@lyopc548.in2p3.fr>" | |
| 7 | 7 | ||
| 8 | - import numpy as N | ||
| 8 | + import numpy as np | ||
| 9 | 9 | ||
| 10 | 10 | def sankey(ax, | |
| 11 | 11 | outputs=[100.], outlabels=None, | |
@@ -30,19 +30,19 @@ def sankey(ax, | |||
| 30 | 30 | import matplotlib.patches as mpatches | |
| 31 | 31 | from matplotlib.path import Path | |
| 32 | 32 | ||
| 33 | - outs = N.absolute(outputs) | ||
| 34 | - outsigns = N.sign(outputs) | ||
| 33 | + outs = np.absolute(outputs) | ||
| 34 | + outsigns = np.sign(outputs) | ||
| 35 | 35 | outsigns[-1] = 0 # Last output | |
| 36 | 36 | ||
| 37 | - ins = N.absolute(inputs) | ||
| 38 | - insigns = N.sign(inputs) | ||
| 37 | + ins = np.absolute(inputs) | ||
| 38 | + insigns = np.sign(inputs) | ||
| 39 | 39 | insigns[0] = 0 # First input | |
| 40 | 40 | ||
| 41 | 41 | assert sum(outs)==100, "Outputs don't sum up to 100%" | |
| 42 | 42 | assert sum(ins)==100, "Inputs don't sum up to 100%" | |
| 43 | 43 | ||
| 44 | 44 | def add_output(path, loss, sign=1): | |
| 45 | - h = (loss/2+w)*N.tan(outangle/180.*N.pi) # Arrow tip height | ||
| 45 | + h = (loss/2+w)*np.tan(outangle/180.*np.pi) # Arrow tip height | ||
| 46 | 46 | move,(x,y) = path[-1] # Use last point as reference | |
| 47 | 47 | if sign==0: # Final loss (horizontal) | |
| 48 | 48 | path.extend([(Path.LINETO,[x+dx,y]), | |
@@ -64,7 +64,7 @@ def add_output(path, loss, sign=1): | |||
| 64 | 64 | outtips.append((sign,path[-5][1])) | |
| 65 | 65 | ||
| 66 | 66 | def add_input(path, gain, sign=1): | |
| 67 | - h = (gain/2)*N.tan(inangle/180.*N.pi) # Dip depth | ||
| 67 | + h = (gain/2)*np.tan(inangle/180.*np.pi) # Dip depth | ||
| 68 | 68 | move,(x,y) = path[-1] # Use last point as reference | |
| 69 | 69 | if sign==0: # First gain (horizontal) | |
| 70 | 70 | path.extend([(Path.LINETO,[x-dx,y]), | |
@@ -109,7 +109,7 @@ def revert(path): | |||
| 109 | 109 | path = urpath + revert(lrpath) + llpath + revert(ulpath) | |
| 110 | 110 | ||
| 111 | 111 | codes,verts = zip(*path) | |
| 112 | - verts = N.array(verts) | ||
| 112 | + verts = np.array(verts) | ||
| 113 | 113 | ||
| 114 | 114 | # Path patch | |
| 115 | 115 | path = Path(verts,codes) | |
@@ -168,15 +168,15 @@ def put_labels(labels,positions,output=True): | |||
| 168 | 168 | ||
| 169 | 169 | if __name__=='__main__': | |
| 170 | 170 | ||
| 171 | - import matplotlib.pyplot as P | ||
| 171 | + import matplotlib.pyplot as plt | ||
| 172 | 172 | ||
| 173 | 173 | outputs = [10.,-20.,5.,15.,-10.,40.] | |
| 174 | 174 | outlabels = ['First','Second','Third','Fourth','Fifth','Hurray!'] | |
| 175 | 175 | outlabels = [ s+'\n%d%%' % abs(l) for l,s in zip(outputs,outlabels) ] | |
| 176 | 176 | ||
| 177 | 177 | inputs = [60.,-25.,15.] | |
| 178 | 178 | ||
| 179 | - fig = P.figure() | ||
| 179 | + fig = plt.figure() | ||
| 180 | 180 | ax = fig.add_subplot(1,1,1, xticks=[],yticks=[], | |
| 181 | 181 | title="Sankey diagram" | |
| 182 | 182 | ) | |
@@ -187,5 +187,5 @@ def put_labels(labels,positions,output=True): | |||
| 187 | 187 | outtexts[1].set_color('r') | |
| 188 | 188 | outtexts[-1].set_fontweight('bold') | |
| 189 | 189 | ||
| 190 | - P.show() | ||
| 190 | + plt.show() | ||
| 191 | 191 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,17 +1,6 @@ | |||
| 1 | 1 | import numpy as np | |
| 2 | - from pylab import figure, show | ||
| 3 | 2 | ||
| 4 | 3 | ||
| 5 | - X = np.random.rand(100, 200) | ||
| 6 | - xs = np.mean(X, axis=1) | ||
| 7 | - ys = np.std(X, axis=1) | ||
| 8 | - | ||
| 9 | - fig = figure() | ||
| 10 | - ax = fig.add_subplot(211) | ||
| 11 | - ax.set_title('click on point to plot time series') | ||
| 12 | - line, = ax.plot(xs, ys, 'o', picker=5) # 5 points tolerance | ||
| 13 | - ax2 = fig.add_subplot(212) | ||
| 14 | - | ||
| 15 | 4 | class PointBrowser: | |
| 16 | 5 | """ | |
| 17 | 6 | Click on a point to select and highlight it -- the data that | |
@@ -74,9 +63,23 @@ def update(self): | |||
| 74 | 63 | fig.canvas.draw() | |
| 75 | 64 | ||
| 76 | 65 | ||
| 77 | - browser = PointBrowser() | ||
| 66 | + if __name__ == '__main__': | ||
| 67 | + import matplotlib.pyplot as plt | ||
| 68 | + | ||
| 69 | + X = np.random.rand(100, 200) | ||
| 70 | + xs = np.mean(X, axis=1) | ||
| 71 | + ys = np.std(X, axis=1) | ||
| 72 | + | ||
| 73 | + fig = plt.figure() | ||
| 74 | + ax = fig.add_subplot(211) | ||
| 75 | + ax.set_title('click on point to plot time series') | ||
| 76 | + line, = ax.plot(xs, ys, 'o', picker=5) # 5 points tolerance | ||
| 77 | + ax2 = fig.add_subplot(212) | ||
| 78 | + | ||
| 79 | + browser = PointBrowser() | ||
| 80 | + | ||
| 81 | + fig.canvas.mpl_connect('pick_event', browser.onpick) | ||
| 82 | + fig.canvas.mpl_connect('key_press_event', browser.onpress) | ||
| 78 | 83 | ||
| 79 | - fig.canvas.mpl_connect('pick_event', browser.onpick) | ||
| 80 | - fig.canvas.mpl_connect('key_press_event', browser.onpress) | ||
| 84 | + plt.show() | ||
| 81 | 85 | ||
| 82 | - show() | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments