最近开始学习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基本的用法。

PS:下面举个示例

本文记录了python中的数据可视化——散点图scatter,令x作为数据(50个点,每个30维),我们仅可视化前两维。labels为其类别(假设有三类)。

这里的x就用random来了,具体数据具体分析。

label设定为[1:20]->1, [21:35]->2, [36:50]->3,(python中数组连接方法:先强制转为list,用+,再转回array)

用matplotlib的scatter绘制散点图,legend和matlab中稍有不同,详见代码。

x = rand(50,30)

from numpy import *

import matplotlib

import matplotlib.pyplot as plt

#basic

f1 = plt.figure(1)

plt.subplot(211)

plt.scatter(x[:,1],x[:,0])

# with label

plt.subplot(212)

label = list(ones(20))+list(2*ones(15))+list(3*ones(15))

label = array(label)

plt.scatter(x[:,1],x[:,0],15.0*label,15.0*label)

# with legend

f2 = plt.figure(2)

idx_1 = find(label==1)

p1 = plt.scatter(x[idx_1,1], x[idx_1,0], marker = 'x', color = 'm', label='1', s = 30)

idx_2 = find(label==2)

p2 = plt.scatter(x[idx_2,1], x[idx_2,0], marker = '+', color = 'c', label='2', s = 50)

idx_3 = find(label==3)

p3 = plt.scatter(x[idx_3,1], x[idx_3,0], marker = 'o', color = 'r', label='3', s = 15)

plt.legend(loc = 'upper right')

result:

figure(1):

figure(2):

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

本文标题: Python中scatter函数参数及用法详解

本文地址: http://www.cppcns.com/jiaoben/python/210361.html

python scatter参数详解_Python中scatter函数参数及用法详解相关推荐

  1. python中tile的用法_python3中numpy函数tile的用法详解

    tile函数位于python模块 numpy.lib.shape_base中,他的功能是重复某个数组.比如tile(A,n),功能是将数组A重复n次,构成一个新的数组,我们还是使用具体的例子来说明问题 ...

  2. python中seek(10、1)_Python中index()和seek()的用法(详解)

    1.index() 一般用处是在序列中检索参数并返回第一次出现的索引,没找到就会报错,比如: >>> t=tuple('Allen') >>> t ('A', 'l ...

  3. python中index什么意思_Python中index()和seek()的用法(详解)

    1.index() 一般用处是在序列中检索参数并返回第一次出现的索引,没找到就会报错,比如: >>> t=tuple('Allen') >>> t ('A', 'l ...

  4. python 遍历函数用法_python中enumerate函数遍历元素用法分析

    本文实例讲述了python中enumerate函数遍历元素用法.分享给大家供大家参考,具体如下: enumerate函数用于遍历序列中的元素以及它们的下标 示例代码如下: i = 0 seq = [' ...

  5. python scatter参数详解_Python 中 scatter 函数参数及用法详解

    Python 中 scatter 函数参数及用法详解 Python 中 scatter 函数参数及用法详解 这里有新鲜出炉的 Python 教程, 程序狗速度看过来! Python 编程语言 Pyth ...

  6. python向量机使用方法_Python中支持向量机SVM的使用方法详解

    除了在Matlab中使用PRTools工具箱中的svm算法,Python中一样可以使用支持向量机做分类.因为Python中的sklearn库也集成了SVM算法,本文的运行环境是Pycharm. 一.导 ...

  7. python中的super用法详解_Python中super函数用法实例分析

    本文实例讲述了python中super函数用法.分享给大家供大家参考,具体如下: 这是个高大上的函数,在python装13手册里面介绍过多使用可显得自己是高手 23333. 但其实他还是很重要的. 简 ...

  8. python的常量和变量_python中的常量和变量代码详解

    局部和全局变量: # name='lhf' # def change_name(): # # global name # name='帅了一比' # print('change_name',name) ...

  9. python中zip函数详解_Python中zip函数用法

    看openstack的代码,遇到一个内建函数zip不明白其意思: # Adjust the weights in the grid by the functions weight adjustment ...

最新文章

  1. 数据结构-图论-拓扑排序模板题(hdu3342)(poj1270)(hdu4857)
  2. Linux 查看命令路径 以及相关信息
  3. OpenBSD 5.1 正式版发布
  4. [网站seo优化] 史上最全增加外链的方法!
  5. (76)FPGA随机函数($dist_uniform)
  6. nginx的目录结构和配置文件
  7. 频繁项目集java实现_关联分析(2):Apriori产生频繁项集
  8. 法国PSA集团宣布,2018年就推出自动驾驶技术
  9. .NET中Web Service的异常机制
  10. 大脑计算机马云,人类和计算机谁更聪明?马云和马斯克在2019世界人工智能大会机智交锋...
  11. [翻译]XNA 3.0 Game Programming Recipes之six
  12. wifi 协议栈的历史的总结
  13. ie 无人操作自动关闭_Win10系统下ie浏览器无响应白屏自动关闭如何修复
  14. google翻译退出中国后如何仍然使用windows版本
  15. 初学51单片机--网上教程(51自学网)
  16. PPT母版制作及自定义主题
  17. 2020世界人工智能大会 -- 落地AI,赋能未来
  18. 高等流体力学复习04
  19. mht转换html delphi,delphi – 创建*. Mht文件(网络档案)
  20. Microsoft Excel 直方图

热门文章

  1. QT使用RabbitMQ
  2. 苹果税要崩溃了!又一国家做出判决:iOS必须开放第三方支付
  3. 笔记本电脑没有wifi图标导致没有网
  4. Springboot 导出word,动态填充表格数据
  5. Go实战--也许最快的Go语言Web框架kataras/iris初识四(i18n、filelogger、recaptcha)
  6. Regionals 2014 Asia - Daejeon
  7. Edge被恶意篡改主页
  8. 解决网页无法选中文字,无法复制的问题
  9. 21考研上岸吉大人工智能学院考研复习策略
  10. ELGamal 加密算法及Java实现