小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

python 散點(diǎn)圖

 wenasunny 2018-08-09

最近開始學(xué)習(xí)python編程,遇到scatter函數(shù),感覺(jué)里面的參數(shù)不知道什么意思于是查資料,最后總結(jié)如下:

1、scatter函數(shù)原型

2、其中散點(diǎn)的形狀參數(shù)marker如下:

3、其中顏色參數(shù)c如下:

4、基本的使用方法如下:

  1. #導(dǎo)入必要的模塊  
  2. import numpy as np  
  3. import matplotlib.pyplot as plt  
  4. #產(chǎn)生測(cè)試數(shù)據(jù)  
  5. x = np.arange(1,10)  
  6. y = x  
  7. fig = plt.figure()  
  8. ax1 = fig.add_subplot(111)  
  9. #設(shè)置標(biāo)題  
  10. ax1.set_title('Scatter Plot')  
  11. #設(shè)置X軸標(biāo)簽  
  12. plt.xlabel('X')  
  13. #設(shè)置Y軸標(biāo)簽  
  14. plt.ylabel('Y')  
  15. #畫散點(diǎn)圖  
  16. ax1.scatter(x,y,c = 'r',marker = 'o')  
  17. #設(shè)置圖標(biāo)  
  18. plt.legend('x1')  
  19. #顯示所畫的圖  
  20. plt.show()  

結(jié)果如下:

5、當(dāng)scatter后面參數(shù)中數(shù)組的使用方法,如s,當(dāng)s是同x大小的數(shù)組,表示x中的每個(gè)點(diǎn)對(duì)應(yīng)s中一個(gè)大小,其他如c,等用法一樣,如下:

(1)、不同大小

  1. #導(dǎo)入必要的模塊  
  2. import numpy as np  
  3. import matplotlib.pyplot as plt  
  4. #產(chǎn)生測(cè)試數(shù)據(jù)  
  5. x = np.arange(1,10)  
  6. y = x  
  7. fig = plt.figure()  
  8. ax1 = fig.add_subplot(111)  
  9. #設(shè)置標(biāo)題  
  10. ax1.set_title('Scatter Plot')  
  11. #設(shè)置X軸標(biāo)簽  
  12. plt.xlabel('X')  
  13. #設(shè)置Y軸標(biāo)簽  
  14. plt.ylabel('Y')  
  15. #畫散點(diǎn)圖  
  16. sValue = x*10  
  17. ax1.scatter(x,y,s=sValue,c='r',marker='x')  
  18. #設(shè)置圖標(biāo)  
  19. plt.legend('x1')  
  20. #顯示所畫的圖  
  21. plt.show()  

(2)、不同顏色

  1. #導(dǎo)入必要的模塊  
  2. import numpy as np  
  3. import matplotlib.pyplot as plt  
  4. #產(chǎn)生測(cè)試數(shù)據(jù)  
  5. x = np.arange(1,10)  
  6. y = x  
  7. fig = plt.figure()  
  8. ax1 = fig.add_subplot(111)  
  9. #設(shè)置標(biāo)題  
  10. ax1.set_title('Scatter Plot')  
  11. #設(shè)置X軸標(biāo)簽  
  12. plt.xlabel('X')  
  13. #設(shè)置Y軸標(biāo)簽  
  14. plt.ylabel('Y')  
  15. #畫散點(diǎn)圖  
  16. cValue = ['r','y','g','b','r','y','g','b','r']  
  17. ax1.scatter(x,y,c=cValue,marker='s')  
  18. #設(shè)置圖標(biāo)  
  19. plt.legend('x1')  
  20. #顯示所畫的圖  
  21. plt.show()  

結(jié)果:

(3)、線寬linewidths

  1. #導(dǎo)入必要的模塊  
  2. import numpy as np  
  3. import matplotlib.pyplot as plt  
  4. #產(chǎn)生測(cè)試數(shù)據(jù)  
  5. x = np.arange(1,10)  
  6. y = x  
  7. fig = plt.figure()  
  8. ax1 = fig.add_subplot(111)  
  9. #設(shè)置標(biāo)題  
  10. ax1.set_title('Scatter Plot')  
  11. #設(shè)置X軸標(biāo)簽  
  12. plt.xlabel('X')  
  13. #設(shè)置Y軸標(biāo)簽  
  14. plt.ylabel('Y')  
  15. #畫散點(diǎn)圖  
  16. lValue = x  
  17. ax1.scatter(x,y,c='r',s= 100,linewidths=lValue,marker='o')  
  18. #設(shè)置圖標(biāo)  
  19. plt.legend('x1')  
  20. #顯示所畫的圖  
  21. plt.show()  


                     注:  這就是scatter基本的用法。             

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多