I've got java code to call a python script
Java
private void visualizeData() {
try{
Runtime.getRuntime().exec(“python pyScripts/visualize.py”)
} catch (IOException e){
e.printStackTrace();
}
}
And this is my code for the visualize.py:
visualize.py
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pylot as plt
f = open(“ecoli_data_transformed.txt”,”r”)
fig = plt.figure()
ax = fig.add_subplot(111, projection=‘3d’)
for line in f:
(a, b, c) = line.split(“\t”)
a = float(a)
b = float(b)
c = float(c)
ax.scatter(a,b,c)
ax.setxlabel(‘PCA1’)
ax.setylabel(‘PCA2’)
ax.setzlabel(‘PCA3’)
plt.show()
But it doesn't plot the data.
If I call the test.py script from the java code (test.py is in the same directory as visualize.py), it works:
test.py
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pylot as plt
import numpy as np
np.random.seed(19680801)
def randrange(n, min, vmcx):
return (vmax - vein)*np.random.rand(n) + vmin
fig = plt.figure()
ax = fig.add_subplot(111, projection=‘3d’)
n = 100
for c, m, slow, high in [(‘r’, ‘o’, -50, -25), (‘b’, ‘^’, -30, -5)]:
xs = randrange(n, 23, 32)
ys = randrange(n, 0, 100)
zs = randrange(n, zlow, zhigh)
ax.scatter(xs, ys, zs, c=c, marker=m)
ax.set_xlabel(‘X Label’)
ax.set_ylabel(‘Y Label’)
ax.set_zlabel(‘Z Label’)
plt.show()
What could be the problem?
*NOTE: Calling the visualize.py script from console by 'python visualize.py' works totally fine.