
-
Kangaroo
This is my program:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as pltfig = plt.figure()
ax = fig.add_subplot(111, projection='3d')x =[1,2,3,4,5,6,7,8,9,10]
y =[5,6,2,3,13,4,1,2,4,8]
z =[2,3,3,3,5,7,9,11,9,10]ax.scatter(x, y, z, c='r', marker='o')
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')plt.show()
I don't know why my graph is fixed in one position.It is difficult to check every point when my data become larger.
So,I want to make my graph rotating automatically since it is easy to view every point.
Does anyone can help me? -
Kangaroo
Thank you guys! I solved my problem by importing numpy! Thanks again!
-
Kangaroo
I got a file of 100 line, each line contains 5 elements such as
Aberdeen,City,189120,57.14369,-2.09814
Corresponse to places,type,population,latitude,longitude respectively
I splited them in 5 arrays and want to use function sorted(population) to rewrite this file ordered by increasing population size.
However, I can't match them in a right order when I sorted(population),eg.Aberdeen,City,59122,57.14369,-2.09814
I just made population in a increasing order. -
Kangaroo
Thank you guys! I do have a blank line in my file but now it's gone!
-
Kangaroo
Stake:
print('x =',splitUP[0],'and y =',splitUP[1]);
IndexError: list index out of range -
Kangaroo
This is my data
2 1.69
3 3.25
4 2.44
5 3.45
6 6.29
7 3.94
8 5.23
9 5.78
10 6.31
11 8.25
12 7.84Stake:
---------------------------below is my program----------------------------
import matplotlib.pyplot as plt;
x = [ ];
y = [ ];readFile = open('xy.txt','r');
for line in readFile:
print(line); splitUP = line.split(); print('x =',splitUP[0],'and y =',splitUP[1]); x.append(splitUP[0]); y.append(splitUP[1]);
readFile.close();
plt.plot(x,y);
plt.show();
-
Kangaroo
import matplotlib.pyplot as plt;
x = [ ];
y = [ ];readFile = open('xy.txt','r');
for line in readFile:
# file is open with a line in variable 'line'
# do something with this line
print(line);
# split the line based on whitespace
splitUP = line.split();print('x = ',splitUP[0],'and y = ',splitUP[1]); # add x and y to the arrays x.append(splitUP[0]); y.append(splitUP[1]);
When I run it , it shows IndexError: list index out of the range