3d Plot不包含所有列数据?

时间:2018-04-04 22:34:02

标签: python numpy

我已经创建了python代码来读取csv文件,将其写入临时文件[" dump2.csv"]并在其上运行简单的统计信息。程序的这一部分工作正常,但是,当我编写3D绘图时 - 我得到了一个很好看的情节但是,它似乎不包括所有的列数据(例如109个案例 - 我将展示我的3D附加的jpg / pic中的图形输出)。任何答案? 这是我的代码:



import numpy as np
import csv as csv
import time
# import pandas as pd
# import pandas as pd
# import statistics

# ======================================================
# MY ATTEMPT AT ACCOUNTING FOR MISSING DATA via adding a "." to blank entries
with open('totaleval4.csv') as fin, open('dump2.csv','wt', newline='') as fout:
    csvin = csv.reader(fin)
    csvout = csv.writer(fout)
    for row in csvin:
        # this "FOR/ELSE" statement - takes the missing ('.') data and codes
        #....it for "999999" and if there is no missing data - it simply writes
        # it.  These operations are reading-in "totaltest2.csv" and writing
        # it's findings ...to the "dump1.csv" file
        #==========This IF statement looks for blank cells (" ") and it a cell
        # is NOT blank - it writes the row - if it is it deletes it from
        # the output    
            if "." not in row:
                csvout.writerow(row)
# fout.close()
# MISSING DATA IS ACCOUNTED FOR AT THIS POINT - AND PRINTED DATA SET WITH NEW 
#....missing data code - inserted in new file (e.g., here "dump.csv")
# ======================================
# Statistical Analysis for new 'dump.csv' file accounting for missing data...
# Statistical Analysis for new 'dump.csv' file accounting for missing data...
readdata = csv.reader(open('dump2.csv', 'r'))
data = []
for row in readdata:
    data.append(row)
Header = data[0]
data.pop(0)
year = []
enrol = []
q2 = []
q3 = []
q4 = []
q5 = []
q6 = []
q8 = []
q9 = []
q10 = []
q11 = []
q12 = []
q13 = []
# =============================
# =============================
for i in range(len(data)):
  year.append(int(data[i][1]))
  enrol.append(int(data[i][3]))
  q2.append(int(data[i][4]))
  q3.append(int(data[i][5]))
  q4.append(int(data[i][6]))
  q5.append(int(data[i][7]))
  q6.append(int(data[i][8]))
  q8.append(int(data[i][9]))
  q9.append(int(data[i][10]))
  q10.append(int(data[i][11]))
  q11.append(int(data[i][12]))
  q12.append(int(data[i][13]))
  q13.append(int(data[i] [14]))
# ==============================
# ==============================
  #  Statistical work-ups/section
# ==============================
print ('Mean Number of Students:        ', (np.mean(enrol)))
print ('Mean 0-5 Question-2:            ', (np.mean(q2)))
print ('Mean 0-5 Question-3:            ', (np.mean(q3)))
print ('Mean 0-5 Question-4:            ', (np.mean(q4)))
print ('Mean 0-5 Question-5:            ', (np.mean(q5)))
print ('Mean 0-5 Question-6:            ', (np.mean(q6)))
print ('Mean 0-5 Question-8:            ', (np.mean(q8)))
print ('Mean 0-5 Question-9:            ', (np.mean(q9)))
print ('Mean 0-5 Question-10:           ', (np.mean(q10)))
print ('Mean 0-5 Question-11:           ', (np.mean(q11)))
print ('Mean 0-5 Question-12:           ', (np.mean(q12)))
print ('Mean 0-5 Question-13:           ', (np.mean(q13)))
print ('Std of Number of Students       ', (np.std(enrol)))
print ('Std of 0-5 Question-2           ', (np.std(q2)))
# ======================================================
time.sleep(2)
# ======================================================
# ======= 3D Graph Code ========
# =======3D Scatter Plot========
# ==============================
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np


fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
x = [year]
y = [q2]
z = [q3]

ax.scatter(x, y, z, c='r', marker='o')

ax.set_xlim(2013, 2018)
ax.set_ylim(0, 6)
ax.set_zlim(0, 6)
ax.set_xlabel('yr')
ax.set_ylabel('q2')
ax.set_zlabel('q3')

plt.show()
time.sleep(2)




图表输出为: John's Stats and 3D Graph output from above code

0 个答案:

没有答案