x2 = L2*sin(y[:,2]) + x1
y2 = -L2*cos(y[:,2]) + y1

fig = plt.figure()
ax = fig.add_subplot(111, autoscale_on=False, xlim=(-2, 2), ylim=(-2, 2))
ax.grid()

line, = ax.plot([], [], 'o-', lw=2)
time_template = 'time = %.1fs'
time_text = ax.text(0.05, 0.9, '', transform=ax.transAxes)

def init():
    line.set_data([], [])
    time_text.set_text('')
    return line, time_text

def animate(i):
    thisx = [0, x1[i], x2[i]]
    thisy = [0, y1[i], y2[i]]

    line.set_data(thisx, thisy)
    time_text.set_text(time_template%(i*dt))
    return line, time_text

ani = animation.FuncAnimation(fig, animate, np.arange(1, len(y)),
    interval=50, blit=False, init_func=init)


serve_figure.serve_figure(fig)
ax.grid()

line, = ax.plot([], [], 'o-', lw=2)
time_template = 'time = %.1fs'
time_text = ax.text(0.05, 0.9, '', transform=ax.transAxes)


def init():
    line.set_data([], [])
    time_text.set_text('')
    return line, time_text


def animate(i):
    thisx = [0, x1[i], x2[i]]
    thisy = [0, y1[i], y2[i]]

    line.set_data(thisx, thisy)
    time_text.set_text(time_template % (i * dt))
    return line, time_text


ani = animation.FuncAnimation(fig,
                              animate,
                              np.arange(1, len(y)),
                              interval=50,
                              blit=False,
                              init_func=init)

serve_figure.serve_figure(fig)
Exemplo n.º 3
0
import numpy as np
from numpy import ma
from matplotlib import pyplot as plt

n = 12

x = np.linspace(-1.5, 1.5, n)
y = np.linspace(-1.5, 1.5, n * 2)
X, Y = np.meshgrid(x, y)
Qx = np.cos(Y) - np.cos(X)
Qz = np.sin(Y) + np.sin(X)
Qx = (Qx + 1.1)
Z = np.sqrt(X ** 2 + Y ** 2) / 5
Z = (Z - Z.min()) / (Z.max() - Z.min())

# The color array can include masked values:
Zm = ma.masked_where(np.fabs(Qz) < 0.5 * np.amax(Qz), Z)

fig = plt.figure()
ax = fig.add_subplot(121)
ax.set_facecolor("#bdb76b")
ax.pcolormesh(Qx, Qz, Z, shading='gouraud')
ax.set_title('Without masked values')

ax = fig.add_subplot(122)
ax.set_facecolor("#bdb76b")
col = ax.pcolormesh(Qx, Qz, Zm, shading='gouraud')
ax.set_title('With masked values')

serve_figure.serve_figure(fig, port=8888)
Exemplo n.º 4
0
import serve_figure

import numpy as np
from matplotlib import pyplot as plt

n = 30

x = np.linspace(-1.5, 1.5, n)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.set_facecolor("#bdb76b")
ax.plot(x, np.sin(x))
ax.set_title('Without masked values')

serve_figure.serve_figure(fig, port=8888)