亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

Python中scatter函數參數詳解

標簽:
Python

最近开始学习Python编程,遇到scatter函数,感觉里面的参数不知道什么意思于是查资料,最后总结如下:

1、scatter函数原型

2、其中散点的形状参数marker如下:

3、其中颜色参数c如下:

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

  1. #导入必要的模块  

  2. import numpy as np  

  3. import matplotlib.pyplot as plt  

  4. #产生测试数据  

  5. x = np.arange(1,10)  

  6. y = x  

  7. fig = plt.figure()  

  8. ax1 = fig.add_subplot(111)  

  9. #设置标题  

  10. ax1.set_title('Scatter Plot')  

  11. #设置X轴标签  

  12. plt.xlabel('X')  

  13. #设置Y轴标签  

  14. plt.ylabel('Y')  

  15. #画散点图  

  16. ax1.scatter(x,y,c = 'r',marker = 'o')  

  17. #设置图标  

  18. plt.legend('x1')  

  19. #显示所画的图  

  20. plt.show()  

结果如下:

5、当scatter后面参数中数组的使用方法,如s,当s是同x大小的数组,表示x中的每个点对应s中一个大小,其他如c,等用法一样,如下:

(1)、不同大小

  1. #导入必要的模块  

  2. import numpy as np  

  3. import matplotlib.pyplot as plt  

  4. #产生测试数据  

  5. x = np.arange(1,10)  

  6. y = x  

  7. fig = plt.figure()  

  8. ax1 = fig.add_subplot(111)  

  9. #设置标题  

  10. ax1.set_title('Scatter Plot')  

  11. #设置X轴标签  

  12. plt.xlabel('X')  

  13. #设置Y轴标签  

  14. plt.ylabel('Y')  

  15. #画散点图  

  16. sValue = x*10  

  17. ax1.scatter(x,y,s=sValue,c='r',marker='x')  

  18. #设置图标  

  19. plt.legend('x1')  

  20. #显示所画的图  

  21. plt.show()  

(2)、不同颜色

  1. #导入必要的模块  

  2. import numpy as np  

  3. import matplotlib.pyplot as plt  

  4. #产生测试数据  

  5. x = np.arange(1,10)  

  6. y = x  

  7. fig = plt.figure()  

  8. ax1 = fig.add_subplot(111)  

  9. #设置标题  

  10. ax1.set_title('Scatter Plot')  

  11. #设置X轴标签  

  12. plt.xlabel('X')  

  13. #设置Y轴标签  

  14. plt.ylabel('Y')  

  15. #画散点图  

  16. cValue = ['r','y','g','b','r','y','g','b','r']  

  17. ax1.scatter(x,y,c=cValue,marker='s')  

  18. #设置图标  

  19. plt.legend('x1')  

  20. #显示所画的图  

  21. plt.show()  

结果:

(3)、线宽linewidths

  1. #导入必要的模块  

  2. import numpy as np  

  3. import matplotlib.pyplot as plt  

  4. #产生测试数据  

  5. x = np.arange(1,10)  

  6. y = x  

  7. fig = plt.figure()  

  8. ax1 = fig.add_subplot(111)  

  9. #设置标题  

  10. ax1.set_title('Scatter Plot')  

  11. #设置X轴标签  

  12. plt.xlabel('X')  

  13. #设置Y轴标签  

  14. plt.ylabel('Y')  

  15. #画散点图  

  16. lValue = x  

  17. ax1.scatter(x,y,c='r',s= 100,linewidths=lValue,marker='o')  

  18. #设置图标  

  19. plt.legend('x1')  

  20. #显示所画的图  

  21. plt.show()  

原文出处

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消