) labels.append( text, regular, origin=(y, -1.05, z), scale=scale, direction=(1, 0, 0), anchor_x="center", anchor_y="top" ) title = "Lorenz strange attractor" labels.append( title, bold, origin=(0, 1.1, z), scale=2 * scale, direction=(1, 0, 0), anchor_x="center", anchor_y="center" ) # Frame # ------------------------------------- P0 = [(xmin, ymin, z), (xmin, ymax, z), (xmax, ymax, z), (xmax, ymin, z)] P1 = [(xmin, ymax, z), (xmax, ymax, z), (xmax, ymin, z), (xmin, ymin, z)] ticks.append(P0, P1, linewidth=2) # Grids # ------------------------------------- n = 11 P0 = np.zeros((n - 2, 3)) P1 = np.zeros((n - 2, 3)) P0[:, 0] = np.linspace(xmin, xmax, n)[1:-1] P0[:, 1] = ymin P0[:, 2] = z P1[:, 0] = np.linspace(xmin, xmax, n)[1:-1] P1[:, 1] = ymax P1[:, 2] = z ticks.append(P0, P1, linewidth=1, color=(0, 0, 0, 0.25))
# ----------------------------------------------------------------------------- import numpy as np from glumpy import app, glm from glumpy.graphics.collections import SegmentCollection from glumpy.transforms import Position, OrthographicProjection, PanZoom window = app.Window(width=1200, height=600, color=(1,1,1,1)) @window.event def on_draw(dt): window.clear() segments.draw() @window.event def on_key_press(key, modifiers): if key == app.window.key.SPACE: transform.reset() n = 100 P0 = np.dstack((np.linspace(100,1100,n),np.ones(n)* 50,np.zeros(n))).reshape(n,3) P1 = np.dstack((np.linspace(110,1110,n),np.ones(n)*550,np.zeros(n))).reshape(n,3) transform = PanZoom(OrthographicProjection(Position())) segments = SegmentCollection(mode="agg", linewidth='local', transform=transform) segments.append(P0, P1, linewidth = np.linspace(1, 8, n)) segments['antialias'] = 1 window.attach(segments["transform"]) window.attach(segments["viewport"]) app.run()
anchor_y="top") title = "Lorenz strange attractor" labels.append(title, bold, origin=(0, 1.1, z), scale=2 * scale, direction=(1, 0, 0), anchor_x="center", anchor_y="center") # Frame # ------------------------------------- P0 = [(xmin, ymin, z), (xmin, ymax, z), (xmax, ymax, z), (xmax, ymin, z)] P1 = [(xmin, ymax, z), (xmax, ymax, z), (xmax, ymin, z), (xmin, ymin, z)] ticks.append(P0, P1, linewidth=2) # Grids # ------------------------------------- n = 11 P0 = np.zeros((n - 2, 3)) P1 = np.zeros((n - 2, 3)) P0[:, 0] = np.linspace(xmin, xmax, n)[1:-1] P0[:, 1] = ymin P0[:, 2] = z P1[:, 0] = np.linspace(xmin, xmax, n)[1:-1] P1[:, 1] = ymax P1[:, 2] = z ticks.append(P0, P1, linewidth=1, color=(0, 0, 0, .25))
def grid(transform, viewport, scale=1.0): ticks = SegmentCollection(mode="agg", transform=transform, viewport=viewport, linewidth='local', color='local') labels = GlyphCollection(transform=transform, viewport=viewport) # xmin,xmax = 0,800 # ymin,ymax = 0,800 xmin, xmax = -1, 1 nx = 11 dx = (xmax - xmin) / (nx - 1) ymin, ymax = -1, 1 ny = 11 dy = (ymax - ymin) / (ny - 1) z = 0 regular = FontManager.get("OpenSans-Regular.ttf") bold = FontManager.get("OpenSans-Bold.ttf") labels_scale = 0.001 for x in np.linspace(xmin, xmax, nx): text = "%.2f" % (x * scale) labels.append(text, regular, origin=(x, ymin - dy / 2, z), scale=labels_scale, direction=(1, 0, 0), anchor_x="center", anchor_y="top") for y in np.linspace(ymin, ymax, ny): text = "%.2f" % (y * scale) labels.append(text, regular, origin=(xmin - dx / 2, y, z), scale=labels_scale, direction=(1, 0, 0), anchor_x="right", anchor_y="center") title = "H3M example" labels.append(title, bold, origin=(0, xmax + dx, z), scale=2 * labels_scale, direction=(1, 0, 0), anchor_x="center", anchor_y="center") # Frame # ------------------------------------- P0 = [(xmin, ymin, z), (xmin, ymax, z), (xmax, ymax, z), (xmax, ymin, z)] P1 = [(xmin, ymax, z), (xmax, ymax, z), (xmax, ymin, z), (xmin, ymin, z)] ticks.append(P0, P1, linewidth=2) # Grids # ------------------------------------- n = 11 P0 = np.zeros((n - 2, 3)) P1 = np.zeros((n - 2, 3)) P0[:, 0] = np.linspace(xmin, xmax, n)[1:-1] P0[:, 1] = ymin P0[:, 2] = z P1[:, 0] = np.linspace(xmin, xmax, n)[1:-1] P1[:, 1] = ymax P1[:, 2] = z ticks.append(P0, P1, linewidth=1, color=(0, 0, 0, .25)) P0 = np.zeros((n - 2, 3)) P1 = np.zeros((n - 2, 3)) P0[:, 0] = xmin P0[:, 1] = np.linspace(ymin, ymax, n)[1:-1] P0[:, 2] = z P1[:, 0] = xmax P1[:, 1] = np.linspace(ymin, ymax, n)[1:-1] P1[:, 2] = z ticks.append(P0, P1, linewidth=1, color=(0, 0, 0, .25)) # Majors # ------------------------------------- n = 11 P0 = np.zeros((n - 2, 3)) P1 = np.zeros((n - 2, 3)) P0[:, 0] = np.linspace(xmin, xmax, n)[1:-1] P0[:, 1] = ymin - 0.015 P0[:, 2] = z P1[:, 0] = np.linspace(xmin, xmax, n)[1:-1] P1[:, 1] = ymin + 0.025 * (ymax - ymin) P1[:, 2] = z ticks.append(P0, P1, linewidth=1.5) P0[:, 1] = ymax + 0.015 P1[:, 1] = ymax - 0.025 * (ymax - ymin) ticks.append(P0, P1, linewidth=1.5) P0 = np.zeros((n - 2, 3)) P1 = np.zeros((n - 2, 3)) P0[:, 0] = xmin - 0.015 P0[:, 1] = np.linspace(ymin, ymax, n)[1:-1] P0[:, 2] = z P1[:, 0] = xmin + 0.025 * (xmax - xmin) P1[:, 1] = np.linspace(ymin, ymax, n)[1:-1] P1[:, 2] = z ticks.append(P0, P1, linewidth=1.5) P0[:, 0] = xmax + 0.015 P1[:, 0] = xmax - 0.025 * (xmax - xmin) ticks.append(P0, P1, linewidth=1.5) # Minors # ------------------------------------- n = 111 P0 = np.zeros((n - 2, 3)) P1 = np.zeros((n - 2, 3)) P0[:, 0] = np.linspace(xmin, xmax, n)[1:-1] P0[:, 1] = ymin P0[:, 2] = z P1[:, 0] = np.linspace(xmin, xmax, n)[1:-1] P1[:, 1] = ymin + 0.0125 * (ymax - ymin) P1[:, 2] = z ticks.append(P0, P1, linewidth=1) P0[:, 1] = ymax P1[:, 1] = ymax - 0.0125 * (ymax - ymin) ticks.append(P0, P1, linewidth=1) P0 = np.zeros((n - 2, 3)) P1 = np.zeros((n - 2, 3)) P0[:, 0] = xmin P0[:, 1] = np.linspace(ymin, ymax, n)[1:-1] P0[:, 2] = z P1[:, 0] = xmin + 0.0125 * (xmax - xmin) P1[:, 1] = np.linspace(ymin, ymax, n)[1:-1] P1[:, 2] = z ticks.append(P0, P1, linewidth=1) P0[:, 0] = xmax P1[:, 0] = xmax - 0.0125 * (xmax - xmin) ticks.append(P0, P1, linewidth=1) return ticks
def on_draw(dt): window.clear() segments.draw() @window.event def on_key_press(key, modifiers): if key == app.window.key.SPACE: transform.reset() n = 100 P0 = np.dstack((np.linspace(100, 1100, n), np.ones(n) * 50, np.zeros(n))).reshape(n, 3) P1 = np.dstack((np.linspace(110, 1110, n), np.ones(n) * 550, np.zeros(n))).reshape(n, 3) transform = PanZoom(OrthographicProjection(Position())) segments = SegmentCollection(mode="agg", linewidth='local', transform=transform) segments.append(P0, P1, linewidth=np.linspace(1, 8, n)) segments['antialias'] = 1 #collection = SegmentCollection(mode="raw", transform=transform) #collection.append(P0, P1) window.attach(segments["transform"]) window.attach(segments["viewport"]) app.run()
else: save_flag = False filename = sys.argv[1] ndata1 = addData(sys.argv[1], points1, color=(0.2, 0.2, 0.2, -1.0)) tuniq1 = np.unique(ndata1['t']) ndata2 = addData(sys.argv[2], points2, color=(0.2, 0.8, 0.2, 0.7)) tuniq2 = np.unique(ndata2['t']) maxtime = len(tuniq1) # prepare coordinate P0 = np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]]) P1 = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) CP = [(0.9, 0.1, 0.1, 1), (0.1, 0.9, 0.1, 1), (0.1, 0.1, 0.9, 1)] coord.append(P0, P1, color=CP, linewidth=[1, 1, 1]) coord['antialias'] = 1 transform = Trackball(Position()) points1["transform"] = transform points2["transform"] = transform coord['transform'] = transform window.attach(points1["transform"]) window.attach(points1["viewport"]) window.attach(points2["transform"]) window.attach(points2["viewport"]) window.attach(coord["transform"]) window.attach(coord["viewport"]) @window.event