In [23]:
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
%matplotlib inline
import urllib2
import numpy as np

np.set_printoptions(precision=3, suppress=True)
url = ('https://raw.githubusercontent.com/Upward-Spiral-Science'
       '/data/master/syn-density/output.csv')
data = urllib2.urlopen(url)
csv = np.genfromtxt(data, delimiter=",")[1:]

def check_condition(row):
    if row[3] == 0:
        return False
    return True

a = np.apply_along_axis(check_condition, 1, csv)
a = np.where(a == True)[0]
nonZeroMask = csv[a, :]

synDividedMask = np.divide(nonZeroMask[:,4],nonZeroMask[:,3])
synDividedMask = synDividedMask * (64**3)
accurateDataT = np.vstack((nonZeroMask[:,0],nonZeroMask[:,1],nonZeroMask[:,2],synDividedMask))
accurateData = accurateDataT.T

cleaned = accurateData[accurateData[:,0] >= 409]
cleaned = cleaned[cleaned[:,0] <= 3529]
cleaned = cleaned[cleaned[:,1] >= 1564]
cleaned = cleaned[cleaned[:,1] <= 3124]

In [24]:
import math
import matplotlib as mpl
mpl.rcParams['font.size'] = 25
mpl.rc('font',family='Times New Roman')

divisionsx = np.unique(cleaned[:,0])
meanx = np.zeros((2,len(divisionsx)))

divisionsy = np.unique(cleaned[:,1])
meany = np.zeros((2,len(divisionsy)))

divisionsz = np.unique(cleaned[:,2])
meanz = np.zeros((2,len(divisionsz)))

maxlen = np.amax([len(divisionsx),len(divisionsy),len(divisionsz)])
xstep = np.divide(maxlen,len(divisionsx))
ystep = 2
zstep = 8

counter = 0
for d in divisionsx:
    slicex = cleaned[cleaned[:,0] == d]
    meanx[0,counter] = (counter)*xstep
    meanx[1,counter] = np.mean(slicex[:,3])
    counter += 1
    
counter = 0
for d in divisionsy:
    slicey = cleaned[cleaned[:,1] == d]
    meany[0,counter] = (counter)*ystep
    meany[1,counter] = np.mean(slicey[:,3])
    counter += 1
    
counter = 0
for d in divisionsz:
    slicez = cleaned[cleaned[:,2] == d]
    meanz[0,counter] = (counter)*zstep
    meanz[1,counter] = np.mean(slicez[:,3])
    counter += 1
    
#plot it
allmean = [301] * maxlen
fig,ax = plt.subplots()
ax.set_ylim([250,350])
ax.set_title('Avg. Synapse Values: x')
ax.set_yticks([250,275,300,325,350])
ax.set_xticks([0,20,40,60,80])
ax.set_xlabel('x coordinate standardized to 0')
ax.set_ylabel('synaptic density')
ax.plot(allmean,color='black')
ax.plot(meanx[0,:],meanx[1,:],color='blue')
plt.subplots_adjust(left = 0.2)
plt.subplots_adjust(bottom = 0.2)
plt.savefig('Fig2a.pdf', format='pdf', dpi=1000)
plt.show()

fig,ax = plt.subplots()
ax.set_ylim([150,400])
ax.set_title('Avg. Synapse Values: y')
ax.set_yticks([150,200,250,300,350,400])
ax.set_xticks([0,20,40,60,80])
ax.set_xlabel('y coordinate standardized to 0')
ax.set_ylabel('synaptic density', size=20)
ax.plot(allmean,color='black')
ax.plot(meany[0,:],meany[1,:],color='blue')
plt.subplots_adjust(left = 0.2)
plt.subplots_adjust(bottom = 0.2)
plt.savefig('Fig2b.pdf', format='pdf', dpi=1000)
plt.show()

fig,ax = plt.subplots()
ax.set_ylim([260,360])
ax.set_title('Avg. Synapse Values: z')
ax.set_yticks([260,285,310,335,360])
ax.set_xticks([0,20,40,60,80])
ax.set_xlabel('z coordinate standardized to 0')
ax.set_ylabel('synaptic density')
ax.plot(allmean,color='black')
ax.plot(meanz[0,:],meanz[1,:],color='blue')
plt.subplots_adjust(left = 0.2)
plt.subplots_adjust(bottom = 0.2)
plt.savefig('Fig2c.pdf', format='pdf', dpi=1000)
plt.show()



In [ ]: