Skip to content

Instantly share code, notes, and snippets.

@andrewbolster
Created May 29, 2014 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewbolster/2aea91ca7c78e4f5e2cf to your computer and use it in GitHub Desktop.
Save andrewbolster/2aea91ca7c78e4f5e2cf to your computer and use it in GitHub Desktop.
Dan's Homework
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <markdowncell>
# basically, want to parse a file, load values in it into a dictionary (name, x, y, z, r, g, b), and scatter lot them, with labels based on RGB color
# <codecell>
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d.axes3d import Axes3D
import numpy as np
from numpy import random as npr
from collections import namedtuple
import string, random
from operator import attrgetter
DataPoint = namedtuple("DataPoint",['name','x','y','z','r','g','b'])
def genranddata():
chars = 'abcdefghijklmnopqrstuvwxyz'
name = ''.join(random.choice(chars) for _ in range(4))
x,y,z,r,g,b = [ npr.uniform() for _ in range(6)]
return DataPoint(name,x,y,z,r,g,b)
data = [genranddata() for _ in range(10)]
# <codecell>
f = plt.figure(figsize(14,14))
ax = f.add_subplot(1,1,1,projection='3d')
x,y,z,cols = [],[],[],[]
for d in data:
x.append(d.x)
y.append(d.y)
z.append(d.z)
cols.append((d.r,d.g,d.b,1.0))
ax.scatter(x,y,z, s=10, c=cols, marker='o')
# <codecell>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment