def plot_dense_array(<EOL>arr, length=<NUM_LIT>, ranges=None, colors=("<STR_LIT>", "<STR_LIT>"), grid=False, camera_position=(-<NUM_LIT>, <NUM_LIT>, <NUM_LIT:32>), camera_rotation=(-<NUM_LIT>, <NUM_LIT:0.5>, <NUM_LIT>)):
import numpy<EOL>from PIL import Image<EOL>from base64 import b64encode<EOL>from tempfile import TemporaryFile<EOL>from math import sqrt<EOL>from IPython.core.display import display, HTML<EOL>from functools import reduce<EOL>def unfold(arr, dtype=None):<EOL><INDENT>dtype = arr.dtype if dtype is None else dtype<EOL>i = sqrt(arr.shape[<NUM_LIT:2>])<EOL>f_per_row, f_per_column = i, i<EOL>try:<EOL><INDENT>depth, height, width = arr.shape[:]<EOL>arr = arr.reshape((depth*height, width))<EOL>new_arr = numpy.empty((height*f_per_column, width*f_per_row), dtype=dtype)<EOL><DEDENT>except ValueError:<EOL><INDENT>depth, height, width, channel = arr.shape<EOL>arr = arr.reshape((depth*height, width, channel))<EOL>new_arr = numpy.empty((height*f_per_column, width*f_per_row, channel), dtype=dtype)<EOL><DEDENT>for h in range(<NUM_LIT:0>, int(f_per_column)):<EOL><INDENT>for w in range(<NUM_LIT:0>, int(f_per_row)):<EOL><INDENT>val = arr[(f_per_row*h+w)*height : (f_per_row*h+w+<NUM_LIT:1>)*height]<EOL>new_arr[h*height : (h+<NUM_LIT:1>)*height, w*width : (w+<NUM_LIT:1>)*width] = val<EOL><DEDENT><DEDENT>return new_arr<EOL><DEDENT>def hist(arr, ranges, length, color):<EOL><INDENT>hist, bins = numpy.histogramdd(arr, bins=tuple([length]*<NUM_LIT:3>), range=tuple(ranges))<EOL>colors = [int(color[<NUM_LIT:1>:][i*<NUM_LIT:2>:(i+<NUM_LIT:1>)*<NUM_LIT:2>], <NUM_LIT:16>) for i in range(<NUM_LIT:0>, <NUM_LIT:3>)]<EOL>len1d = reduce(lambda val, memo: memo*val, hist.shape, <NUM_LIT:1>)<EOL>arr = [((val/numpy.max(hist))*(hist.copy())).reshape(len1d) for val in colors]<EOL>return numpy.array(arr, dtype=numpy.int8).transpose().reshape(tuple(list(hist.shape) + [<NUM_LIT:3>]))<EOL><DEDENT>ranges = ranges if ranges is not None else [(numpy.min(a), numpy.max(a)) for a in numpy.array(arr).reshape((sum(map(len, arr)), <NUM_LIT:3>)).transpose()]<EOL>hist_arr = [hist(a, ranges, length, colors[i]) for i, a in enumerate(arr)]<EOL>compressed = reduce(lambda p, n: p+n, hist_arr)<EOL>img = Image.fromarray(unfold(compressed), "<STR_LIT>")<EOL>fp = TemporaryFile("<STR_LIT>")<EOL>img.save(fp, "<STR_LIT>")<EOL>fp.seek(<NUM_LIT:0>)<EOL>encoded_url = "<STR_LIT>" + b64encode(fp.read())<EOL>model = {<EOL>'<STR_LIT>': [{<EOL>'<STR_LIT:type>': '<STR_LIT>',<EOL>'<STR_LIT:data>': encoded_url,<EOL>'<STR_LIT>': {<EOL>'<STR_LIT:name>': "<STR_LIT>",<EOL>'<STR_LIT:width>': length,<EOL>'<STR_LIT>': length,<EOL>'<STR_LIT>': length,<EOL>'<STR_LIT>': sqrt(length),<EOL>'<STR_LIT>': sqrt(length)<EOL>}<EOL>}],<EOL>'<STR_LIT>': {<EOL>'<STR_LIT>': grid,<EOL>'<STR_LIT>': True<EOL>}<EOL>}<EOL>model_id = '<STR_LIT>' + str(uuid.uuid4()) + '<STR_LIT:">'<EOL>display(HTML(generate_html(<EOL>{'<STR_LIT>': json.dumps(model), '<STR_LIT>': model_id,<EOL>'<STR_LIT>': camera_position[<NUM_LIT:0>], '<STR_LIT>': camera_position[<NUM_LIT:1>], '<STR_LIT>': camera_position[<NUM_LIT:2>],<EOL>'<STR_LIT>': camera_rotation[<NUM_LIT:0>], '<STR_LIT>': camera_rotation[<NUM_LIT:1>], '<STR_LIT>': camera_rotation[<NUM_LIT:2>]},<EOL>'<STR_LIT>')))<EOL>
Volume renderer

Parameters
----------
arr : list of numpy.array
    i.e. [array([[1,2,3], [2,3,4]]), array([[1,2,3]])]
ranges : list of tuple
    ranges for x, y, and z axis
    i.e. [(-100, 100), (-100, 100), (-100, 100)]
colors : list of string
    colors for species
length : int
    length of the texture
    256 or 64
camera_position : tuple, default (-22, 23, 32)
camera_rotaiton : tuple, default (-0.6, 0.5, 0.6)
    Initial position and rotation of camera.