Example #1
0
from pylab import figure, show, nx
Ntests = 3
t = nx.arange(0.0, 1.0, 0.05)
s = nx.sin(2*nx.pi*t)
fig = figure()
ax = fig.add_subplot(Ntests, 1, 1)
N = 100
x, y = 0.9*nx.mlab.rand(2,N)
area = nx.pi*(10 * nx.mlab.rand(N))**2 # 0 to 10 point radiuses
ax.scatter(x,y,s=area, marker='^', c='r', label='scatter')
ax.legend()
ax = fig.add_subplot(Ntests, 1, 2)
ax.vlines(t, [0], nx.sin(2*nx.pi*t), label='vlines')
ax.legend()
ax = fig.add_subplot(Ntests, 1, 3)
ax.plot(t, s, 'b-', lw=2, label='a line')
ax.legend()
fig.savefig('legend_unit')
show()
Example #2
0

See matplotlib.text.Annotation for details
"""
from pylab import figure, show, nx
from matplotlib.patches import Rectangle, CirclePolygon, Ellipse
from matplotlib.text import Annotation

fig = figure()
ax = fig.add_subplot(111, autoscale_on=False, xlim=(-1, 5), ylim=(-1, 5))

rect = Rectangle((0.5, 0.5), 1, 3, alpha=0.3)
ax.add_patch(rect)

t = nx.arange(0.0, 5.0, 0.01)
s = nx.sin(2 * nx.pi * t)
line, = ax.plot(t, s, lw=3, color="purple")

a = Annotation(rect, "A: rect", loc=("outside right", "outside top"), color="blue")
ax.add_artist(a)

b = Annotation(rect, "B: rect", loc=("inside left", "inside top"), autopad=8, color="blue")
ax.add_artist(b)

c = Annotation(rect, "C: rect", loc=("center", "center"), color="blue")
ax.add_artist(c)

d = Annotation(ax, "D: axes", loc=("inside right", "inside bottom"), color="red")
ax.add_artist(d)

e = Annotation(ax, "E: an axes title", loc=("center", "outside top"), color="red")
Example #3
0
#coding: UTF-8
from pylab import figure, nx, show
fig = figure()
ax = fig.add_subplot(111)
t = nx.arange(0.0,3.01,0.01)
s = nx.sin(2*nx.pi*t)
c = nx.sin(4*nx.pi*t)
ax.fill(t, s, 'b', t, c, 'g', alpha=0.2)
show()
from pylab import figure, nx, show

# unit area ellipse
rx, ry = 3., 1.
area = rx * ry * nx.pi
theta = nx.arange(0, 2 * nx.pi + 0.01, 0.1)
verts = zip(rx / area * nx.cos(theta), ry / area * nx.sin(theta))

x, y, s, c = nx.mlab.rand(4, 30)
s *= 10**2.

fig = figure()
ax = fig.add_subplot(111)
ax.scatter(x, y, s, c, marker=None, verts=verts)

show()
Example #5
0
from pylab import figure, show, nx, linspace, stineman_interp
x = linspace(0,2*nx.pi,20);
y = nx.sin(x); yp = None 
xi = linspace(x[0],x[-1],100);
yi = stineman_interp(xi,x,y,yp);

fig = figure()
ax = fig.add_subplot(111)
ax.plot(x,y,'ro',xi,yi,'-b.')
show()

Example #6
0
from matplotlib.widgets import MultiCursor
from pylab import figure, show, nx

t = nx.arange(0.0, 2.0, 0.01)
s1 = nx.sin(2*nx.pi*t)
s2 = nx.sin(4*nx.pi*t)
fig = figure()
ax1 = fig.add_subplot(211)
ax1.plot(t, s1)


ax2 = fig.add_subplot(212, sharex=ax1)
ax2.plot(t, s2)

multi = MultiCursor(fig.canvas, (ax1, ax2), color='r', lw=1)
show()
Example #7
0
from matplotlib.widgets import MultiCursor
from pylab import figure, show, nx

t = nx.arange(0.0, 2.0, 0.01)
s1 = nx.sin(2 * nx.pi * t)
s2 = nx.sin(4 * nx.pi * t)
fig = figure()
ax1 = fig.add_subplot(211)
ax1.plot(t, s1)

ax2 = fig.add_subplot(212, sharex=ax1)
ax2.plot(t, s2)

multi = MultiCursor(fig.canvas, (ax1, ax2), color='r', lw=1)
show()
Example #8
0
    # the difference that comes when using the slopes given in yp
    dy1 = (nx.take(yp, idx)- sidx) * (xi - xidx)       # using the yp slope of the left point
    dy2 = (nx.take(yp, idx+1)-sidx) * (xi - xidxp1) # using the yp slope of the right point

    dy1dy2 = dy1*dy2
    # The following is optimized for Python. The solution actually
    # does more calculations than necessary but exploiting the power
    # of numpy, this is far more efficient than coding a loop by hand
    # in Python
    yi = yo + dy1dy2 * nx.choose(nx.array(nx.sign(dy1dy2), nx.Int32)+1, 
                                 ((2*xi-xidx-xidxp1)/((dy1-dy2)*(xidxp1-xidx)),
                                  0.0,
                                  1/(dy1+dy2),))
        
    return yi

if __name__ == '__main__':
    # Here is some example code

    from pylab import figure, show, nx, linspace

    x = linspace(0,2*nx.pi,20);
    y = nx.sin(x); yp = None 
    xi = linspace(x[0],x[-1],100);
    yi = stineman_interp(xi,x,y,yp);

    fig = figure()
    ax = fig.add_subplot(111)
    ax.plot(x,y,'ro',xi,yi,'-b.')
    show()
Example #9
0
from __future__ import print_function
from pylab import figure, show, nx

Ntests = 3
t = nx.arange(0.0, 1.0, 0.05)
s = nx.sin(2 * nx.pi * t)

# scatter creates a RegPolyCollection
fig = figure()
ax = fig.add_subplot(Ntests, 1, 1)
N = 100
x, y = 0.9 * nx.mlab.rand(2, N)
area = nx.pi * (10 * nx.mlab.rand(N))**2  # 0 to 10 point radiuses
ax.scatter(x, y, s=area, marker='^', c='r', label='scatter')
ax.legend()

# vlines creates a LineCollection
ax = fig.add_subplot(Ntests, 1, 2)
ax.vlines(t, [0], nx.sin(2 * nx.pi * t), label='vlines')
ax.legend()

# vlines creates a LineCollection
ax = fig.add_subplot(Ntests, 1, 3)
ax.plot(t, s, 'b-', lw=2, label='a line')
ax.legend()

fig.savefig('legend_unit')
show()
Example #10
0
from pylab import figure, show, nx, linspace, stineman_interp
x = linspace(0, 2 * nx.pi, 20)
y = nx.sin(x)
yp = None
xi = linspace(x[0], x[-1], 100)
yi = stineman_interp(xi, x, y, yp)

fig = figure()
ax = fig.add_subplot(111)
ax.plot(x, y, 'ro', xi, yi, '-b.')
show()