Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132930 views
License: OTHER
1
def writeCoordinates(file, x, y, z):
2
file.write("(" + str(x) + "," + str(y) + "," + str(z) + ") ")
3
4
def make3dhistogram(x, y, z, zmin, output):
5
file = open(output, 'wb')
6
i = 0
7
for j in range(len(y)):
8
writeCoordinates(file, x[i], y[j], zmin)
9
writeCoordinates(file, x[i], y[j], zmin)
10
file.write("\n\n")
11
for i in range(len(x)-1):
12
writeCoordinates(file, x[i], y[0], zmin)
13
for j in range(len(y)-1):
14
writeCoordinates(file, x[i], y[j], z[i][j])
15
writeCoordinates(file, x[i], y[j+1], z[i][j])
16
writeCoordinates(file, x[i], y[len(y)-1], zmin)
17
writeCoordinates(file, x[i+1], y[0], zmin)
18
file.write("\n\n")
19
for j in range(len(y)-1):
20
writeCoordinates(file, x[i+1], y[j], z[i][j])
21
writeCoordinates(file, x[i+1], y[j+1], z[i][j])
22
writeCoordinates(file, x[i+1], y[len(y)-1], zmin)
23
file.write("\n\n")
24
25
i = len(x)-1
26
for j in range(len(y)):
27
writeCoordinates(file, x[i], y[j], zmin)
28
writeCoordinates(file, x[i], y[j], zmin)
29
30
def createTex(x, y, z, output='3d-manhattan-bar-plot.tex'):
31
template = open('template.tpl', 'r').read()
32
make3dhistogram(x, y, z, 0.0, 'data')
33
data = open('data', 'r').read()
34
file = open(output, 'wb')
35
template = template.replace('[PLACE_PLOT_HERE]', data)
36
template = template.replace('[XMAX]', str(len(x)-1))
37
template = template.replace('[YMAX]', str(len(y)-1))
38
file.write(template)
39
40
if __name__ == "__main__":
41
x = [0,1,2,3,4] # Whats that good for? Can it be replaced by range(xMax+1)?
42
y = [0,1,2,3,4] # Whats that good for? Can it be replaced by range(yMax+1)?
43
z = [[2,3,1,0], [0,6,0,0], [1,0,0,4], [0,0,0,0]]
44
createTex(x,y,z)
45
46