PYthon——plt.scatter各参数详解
来源:互联网 发布:海信淘宝旗舰店 编辑:程序博客网 时间:2024/05/22 10:36
最近开始学习Python编程,遇到scatter函数,感觉里面的参数不知道什么意思于是查资料,最后总结如下:
1、scatter函数原型
2、其中散点的形状参数marker如下:
3、其中颜色参数c如下:
4、基本的使用方法如下:
- #导入必要的模块
- import numpy as np
- import matplotlib.pyplot as plt
- #产生测试数据
- x = np.arange(1,10)
- y = x
- fig = plt.figure()
- ax1 = fig.add_subplot(111)
- #设置标题
- ax1.set_title(’Scatter Plot’)
- #设置X轴标签
- plt.xlabel(’X’)
- #设置Y轴标签
- plt.ylabel(’Y’)
- #画散点图
- ax1.scatter(x,y,c = ’r’,marker = ‘o’)
- #设置图标
- plt.legend(’x1’)
- #显示所画的图
- plt.show()
结果如下:
5、当scatter后面参数中数组的使用方法,如s,当s是同x大小的数组,表示x中的每个点对应s中一个大小,其他如c,等用法一样,如下:
(1)、不同大小
- #导入必要的模块
- import numpy as np
- import matplotlib.pyplot as plt
- #产生测试数据
- x = np.arange(1,10)
- y = x
- fig = plt.figure()
- ax1 = fig.add_subplot(111)
- #设置标题
- ax1.set_title(’Scatter Plot’)
- #设置X轴标签
- plt.xlabel(’X’)
- #设置Y轴标签
- plt.ylabel(’Y’)
- #画散点图
- sValue = x*10
- ax1.scatter(x,y,s=sValue,c=’r’,marker=‘x’)
- #设置图标
- plt.legend(’x1’)
- #显示所画的图
- plt.show()
(2)、不同颜色
- #导入必要的模块
- import numpy as np
- import matplotlib.pyplot as plt
- #产生测试数据
- x = np.arange(1,10)
- y = x
- fig = plt.figure()
- ax1 = fig.add_subplot(111)
- #设置标题
- ax1.set_title(’Scatter Plot’)
- #设置X轴标签
- plt.xlabel(’X’)
- #设置Y轴标签
- plt.ylabel(’Y’)
- #画散点图
- cValue = [’r’,‘y’,‘g’,‘b’,‘r’,‘y’,‘g’,‘b’,‘r’]
- ax1.scatter(x,y,c=cValue,marker=’s’)
- #设置图标
- plt.legend(’x1’)
- #显示所画的图
- plt.show()
结果:
(3)、线宽linewidths
- #导入必要的模块
- import numpy as np
- import matplotlib.pyplot as plt
- #产生测试数据
- x = np.arange(1,10)
- y = x
- fig = plt.figure()
- ax1 = fig.add_subplot(111)
- #设置标题
- ax1.set_title(’Scatter Plot’)
- #设置X轴标签
- plt.xlabel(’X’)
- #设置Y轴标签
- plt.ylabel(’Y’)
- #画散点图
- lValue = x
- ax1.scatter(x,y,c=’r’,s= 100,linewidths=lValue,marker=‘o’)
- #设置图标
- plt.legend(’x1’)
- #显示所画的图
- plt.show()
注: 这就是scatter基本的用法。
阅读全文
0 0
- PYthon——plt.scatter各参数详解
- PYthon——plt.scatter各参数详解
- python scatter参数详解
- Python中scatter函数参数详解
- Python matplotlib库scatter函数参数详解
- scatter函数参数详解
- python 中scatter()函数个参数意思
- 【python】Matplotlib画图(一)——散点图scatter
- python scatter
- Python学习—matplotlib使用—plt.tick_params中which用法
- Using scatter plots for multivariate data —— python data science cookbook
- python函数scatter使用
- ARM Scatter File详解
- ARM Scatter File详解
- 聊聊Linux动态链接中的PLT和GOT(1)——何谓PLT与GOT
- Python matplotlib 线图(plt.plot())
- MATLAB——scatter的简单应用
- MATLAB——scatter的简单应用
- 51nod 1096 距离之和最小 【思维题】
- 代理模式和装饰器模式的区别
- 贷款
- WEB接口测试之Jmeter接口测试自动化 (二)
- bzoj1026
- PYthon——plt.scatter各参数详解
- 算法之贪心书架
- [二分+最大流]51 Nod——1757 大灾变
- 人为什么觉得心累呢?很值得看 !
- tomcat 启动时间过长
- 遮罩锁屏
- Oracle pl/sql 游标
- 剑指offer第22题(从上往下打印二叉树)
- python: pop函数