Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
a[1, i][1] *= -1
return a
np.random.seed(0)
a = np.empty([2, N, 2], dtype=np.float)
a[0, :] = -0.5 + np.random.random((N, 2)) # positions
a[1, :] = -0.5 + np.random.random((N, 2)) # velocities
a[0, :] *= (4 - 2*size)
dt = 1. / 30
step_numba = jit('f8[:,:,:](f8, f8, f8[:,:,:])')(step)
gr.setwindow(-2, 2, -2, 2)
gr.setviewport(0, 1, 0, 1)
gr.setmarkertype(gr.MARKERTYPE_SOLID_CIRCLE)
gr.setmarkersize(1.0)
start = time.time()
t0 = start
n = 0
t = 0
worker = 'CPython'
while t < 6:
if t > 3:
if worker == 'CPython':
t0 = now
n = 0
for plot in self._lstPlot:
plot.sizex, plot.sizey = self.sizex, self.sizey
plot.drawGR()
# logDomainCheck
logXinDomain = plot.logXinDomain()
logYinDomain = plot.logYinDomain()
if logXinDomain != self._logXinDomain:
self._logXinDomain = logXinDomain
self.logXinDomain.emit(self._logXinDomain)
if logYinDomain != self._logYinDomain:
self._logYinDomain = logYinDomain
self.logYinDomain.emit(self._logYinDomain)
if self._pickEvent:
event = self._pickEvent
gr.setviewport(*event.viewport)
wcPoint = event.getWC(event.viewport)
window = gr.inqwindow()
gr.setwindow(*event.getWindow())
gr.setmarkertype(gr.MARKERTYPE_PLUS)
gr.polymarker([wcPoint.x], [wcPoint.y])
gr.setwindow(*window)
if logXinDomain != self._logXinDomain:
self._logXinDomain = logXinDomain
self.logXinDomain.emit(self._logXinDomain)
if logYinDomain != self._logYinDomain:
self._logYinDomain = logYinDomain
self.logYinDomain.emit(self._logYinDomain)
if self._pickEvent:
event = self._pickEvent
gr.setviewport(*event.viewportscaled)
wcPoint = event.getWC(event.viewport)
window = gr.inqwindow()
gr.setwindow(*event.getWindow())
gr.setmarkertype(gr.MARKERTYPE_PLUS)
gr.polymarker([wcPoint.x], [wcPoint.y])
gr.setwindow(*window)
gr.setwindow(-2, 2, -2, 2)
gr.setspace(-0.5, 0.5, 0, 90)
gr.setmarkersize(1)
gr.setmarkertype(gr.MARKERTYPE_SOLID_CIRCLE)
gr.setcharheight(0.024)
gr.settextalign(2, 0)
gr.settextfontprec(3, 0)
x, y, z = gr.gridit(xd, yd, zd, 200, 200)
h = np.linspace(-0.5, 0.5, 20)
gr.surface(x, y, z, 5)
gr.contour(x, y, h, z, 0)
gr.polymarker(xd, yd)
gr.axes(0.25, 0.25, -2, -2, 2, 2, 0.01)
gr.updatews()
"""
import numpy as np
import gr
np.random.seed(0)
xd = np.random.uniform(-2, 2, 100)
yd = np.random.uniform(-2, 2, 100)
zd = xd * np.exp(-xd**2 - yd**2)
gr.setviewport(0.1, 0.95, 0.1, 0.95)
gr.setwindow(-2, 2, -2, 2)
gr.setspace(-0.5, 0.5, 0, 90)
gr.setmarkersize(1)
gr.setmarkertype(gr.MARKERTYPE_SOLID_CIRCLE)
gr.setcharheight(0.024)
gr.settextalign(2, 0)
gr.settextfontprec(3, 0)
x, y, z = gr.gridit(xd, yd, zd, 200, 200)
h = np.linspace(-0.5, 0.5, 20)
gr.surface(x, y, z, 5)
gr.contour(x, y, h, z, 0)
gr.polymarker(xd, yd)
gr.axes(0.25, 0.25, -2, -2, 2, 2, 0.01)
gr.updatews()
width, height = z.shape
cmap = _colormap()
icmap = np.zeros(256, np.uint32)
for i in range(256):
r, g, b, a = cmap[i]
icmap[i] = (int(r*255) << 0) + (int(g*255) << 8) + (int(b*255) << 16) + (int(a*255) << 24)
z_range = np.ptp(z)
if z_range > 0:
data = (z - np.min(z)) / z_range * 255
else:
data = np.zeros((width, height))
rgba = np.zeros((width, height), np.uint32)
for x in range(width):
for y in range(height):
rgba[x, y] = icmap[int(data[x, y])]
gr.drawimage(x_min, x_max, y_min, y_max, width, height, rgba)
_colorbar()
elif kind == 'wireframe':
if x.shape == y.shape == z.shape:
x, y, z = gr.gridit(x, y, z, 50, 50)
gr.setfillcolorind(0)
z.shape = np.prod(z.shape)
gr.surface(x, y, z, gr.OPTION_FILLED_MESH)
_draw_axes(kind, 2)
elif kind == 'surface':
if x.shape == y.shape == z.shape:
x, y, z = gr.gridit(x, y, z, 200, 200)
z.shape = np.prod(z.shape)
if _plt.kwargs.get('accelerate', True):
gr3.clear()
gr3.surface(x, y, z, gr.OPTION_COLORED_MESH)
def gridit(xd, yd, zd, nx, ny):
nd = _assertEqualLength(xd, yd, zd)
_xd = floatarray(nd, xd)
_yd = floatarray(nd, yd)
_zd = floatarray(nd, zd)
x = (c_double * nx)()
y = (c_double * ny)()
z = (c_double * (nx * ny))()
__gr.gr_gridit(c_int(nd), _xd.data, _yd.data, _zd.data,
c_int(nx), c_int(ny), x, y, z)
return [x[:], y[:], z[:]]
data = np.fromfile("mri.raw", np.uint16)
data = data.reshape((64, 64, 93))
data[data > 2000] = 2000
data[:, :, :] = data / 2000.0 * np.iinfo(np.uint16).max
gr.setviewport(0, 1, 0, 1)
gr3.init()
gr3.cameralookat(-3, 2, -2, 0, 0, 0, 0, 0, -1)
mesh = gr3.createisosurfacemesh(data, isolevel=40000)
gr.setcolormap(1)
for z in np.linspace(0, 1, 300):
draw(mesh, x=0.9, z=z)
for y in np.linspace(1, 0.5, 300):
draw(mesh, x=0.9, y=y, z=1)
gr.setcolormap(19)
for x in np.linspace(0.9, 0, 300):
draw(mesh, x=x, y=0.5, z=1)
for x in np.linspace(0, 0.9, 300):
draw(mesh, x=x, z=1)
gr3.terminate()
from numpy.random import uniform, seed
import numpy as np
import gr
seed(0)
xd = uniform(-2, 2, 100)
yd = uniform(-2, 2, 100)
zd = xd * np.exp(-xd**2 - yd**2)
gr.setviewport(0.1, 0.95, 0.1, 0.95)
gr.setwindow(-2, 2, -2, 2)
gr.setspace(-0.5, 0.5, 0, 90)
gr.setmarkersize(1)
gr.setmarkertype(gr.MARKERTYPE_SOLID_CIRCLE)
gr.setcharheight(0.024)
gr.settextalign(2, 0)
gr.settextfontprec(3, 0)
x, y, z = gr.gridit(xd, yd, zd, 200, 200)
h = np.linspace(-0.5, 0.5, 20)
gr.surface(x, y, z, 5)
gr.contour(x, y, h, z, 0)
gr.polymarker(xd, yd)
gr.axes(0.25, 0.25, -2, -2, 2, 2, 0.01)
gr.updatews()
a[1, i][1] *= -1
return a
np.random.seed(0)
a = np.empty([2, N, 2], dtype=float)
a[0, :] = -0.5 + np.random.random((N, 2)) # positions
a[1, :] = -0.5 + np.random.random((N, 2)) # velocities
a[0, :] *= (4 - 2*size)
dt = 1. / 30
step_numba = jit('f8[:,:,:](f8, f8, f8[:,:,:])')(step)
gr.setwindow(-2, 2, -2, 2)
gr.setviewport(0, 1, 0, 1)
gr.setmarkertype(gr.MARKERTYPE_SOLID_CIRCLE)
gr.setmarkersize(1.0)
start = time.time()
t0 = start
n = 0
t = 0
worker = 'CPython'
while t < 6:
if t > 3:
if worker == 'CPython':
t0 = now
n = 0
a = step_numba(dt, size, a)