实验二python语言基础函数包练习.doc
实验二PYTHON语言基础函数包练习姓名季鹏班级1208学号2012301630030实验目的1、熟练掌握PYTHON语言基础函数包,如MATH、NUMPY、SCIPY和MATPLOTLIB等函数包的使用实验内容练习1基本统计可视化STEP1导入编程所需要函数包STEP2柱状图可视化可视化结果(将图粘贴到这个位置)STEP3散点图可视化可视化结果(将图粘贴到这个位置)STEP4BOXPLOT可视化可视化结果(将图粘贴到这个位置)STEP5三次样条插值可视化结果(将图粘贴到这个位置)练习内容1、要求读取某课程期末考试的成绩“SCORESCSV”,字段信息如下ID学号;FSCORE期末考试成绩GROUPE分组组别CLASS班级SCORE1第一次平时成绩SCORE2第二次平时成绩SCORE3第三次平时成绩SCORE最终综合成绩要求1分别画出四个成绩的柱状图,观察是否满足正态分布;2分别拟合第一次、第二次、第三次成绩和期末考试成绩之间的关系;3分别按照班级和组别做BOXPLOT,观察每一组和每一班之间成绩的浮动区间。提示1读取CSV文件IMPORTCSVIN_FILEOPEN SCORESCSV , R CSV_READERCSVREADERIN_FILE,DELIMITER , READTHEHEADERINFOHEADERCSV_READERNEXTPRINTHEADER代码CODINGUTF8IMPORTNUMPYASNPIMPORTSCIPYASSPYIMPORTMATPLOTLIBMLABASMLABIMPORTMATPLOTLIBPYPLOTASPLTFROMSCIPYOPTIMIZEIMPORTLEASTSQIMPORTPYLABASPLIMPORTCSVIN_FILEOPEN E\STUDTSTUDYLEARN\PYTHON\GIS\EXPERIMENT2\EXPERIMENT2\SCORESCSV , R CSV_READERCSVREADERIN_FILE,DELIMITER , READTHEHEADERINFOHEADERCSV_READERNEXTPRINTHEADERDEFINEIDGROUPCLASSFSCORESCORE1SCORE2SCORE3SCOREREADDATAFORLINEINCSV_READERINGNOREFIRSTLINEIFCSV_READERLINE_NUM0CONTINUEIDAPPENDLINE0FSCOREAPPENDLINE1GROUPAPPENDFLOATLINE2CLASSAPPENDFLOATLINE3SCORE1APPENDFLOATLINE4SCORE2APPENDFLOATLINE5SCORE3APPENDFLOATLINE6SCOREAPPENDFLOATLINE7PRINTIDPRINTGROUPPRINTSCOREPLTFIGURE1SCORE1PLTSUBPLOT411N1,BINS1,PATCHES1PLTHISTSCORE1,25,NORMED1,FACECOLOR GREEN ,ALPHA08Y1MLABNORMPDFBINS1,100,15LPLTPLOTBINS1,Y1, R ,LINEWIDTH1PLTXLABEL ID PLTYLABEL SCORE1 PLTTITLE HISTOGRAMOFSCORE SCORE2PLTSUBPLOT412N1,BINS1,PATCHES1PLTHISTSCORE2,25,NORMED1,FACECOLOR RED ,ALPHA08Y1MLABNORMPDFBINS1,100,15LPLTPLOTBINS1,Y1, R ,LINEWIDTH1PLTXLABEL ID PLTYLABEL SCORE2 SCORE3PLTSUBPLOT413N1,BINS1,PATCHES1PLTHISTSCORE3,25,NORMED1,FACECOLOR YELLOW ,ALPHA08Y1MLABNORMPDFBINS1,100,15LPLTPLOTBINS1,Y1, R ,LINEWIDTH1PLTXLABEL ID PLTYLABEL SCORE3 SCOREAX4PLTSUBPLOT414N1,BINS1,PATCHES1PLTHISTSCORE,25,NORMED1,FACECOLOR BLUE ,ALPHA08Y1MLABNORMPDFBINS1,100,15LPLTPLOTBINS1,Y1, R ,LINEWIDTH1PLTXLABEL ID PLTYLABEL SCORE PLTSHOW2222222222222222222222222222222222222PLTFIGURE2FIGPLTFIGURE2DEFPICSCORE1,SCORE,AXIMPORTRANDOMORDER9PLTPLOTSCORE,SCORE1,COLOR M ,LINESTYLE ,MARKER MATAFORIINRANGE0,ORDER1MATA1FORJINRANGE0,ORDER1TX00FORKINRANGE0,LENSCORE1DX10FORLINRANGE0,JIDXDXSCORE1KTXDXMATA1APPENDTXMATAAPPENDMATA1PRINTLENXAPRINTMATA00MATANPARRAYMATAMATBFORIINRANGE0,ORDER1TY00FORKINRANGE0,LENSCORE1DY10FORLINRANGE0,IDYDYSCORE1KTYSCOREKDYMATBAPPENDTYMATBNPARRAYMATBMATAANPLINALGSOLVEMATA,MATBPRINTMATAAYYAFORIINRANGE0,LENSCORE1YY00FORJINRANGE0,ORDER1DY10FORKINRANGE0,JDYSCOREIDYMATAAJYYDYYYAAPPENDYYAXPLOTSCORE,YYA,COLOR G ,LINESTYLE ,MARKER AXLEGENDRETURN1AX1FIGADD_SUBPLOT311PICSCORE1,SCORE,AX1AX2FIGADD_SUBPLOT312PICSCORE2,SCORE,AX2AX3FIGADD_SUBPLOT313PICSCORE3,SCORE,AX333333333333333333AAFORIINRANGELENGROUPIFGROUPINOTINAATEMPGROUPIFORJINRANGELENGROUPIFGROUPJTEMPAAAPPENDTEMPBREAKAX0FORCOLINRANGE5FORROWINRANGELENAAM0N0FORIINRANGELENAAFORJINRANGELENGROUPIFGROUPJAAIAXMNSCOREJNN1MM1N0PRINTAXI0LABELSLISTAAFORIINRANGELENAALABELSAPPENDSTRAAIFS10FIG,AXESPLTSUBPLOTSNROWS1,NCOLSLENAA,FIGSIZ