散点图的应用很广泛,以前介绍过很多画图方法:Python画图(直方图、多张子图、二维图形、三维图形以及图中图),漏掉了这个,现在补上,用法很简单,我们可以help(plt.scatter)看下它的用法:

Help on function scatter in module matplotlib.pyplot:scatter(x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None,
vmax=None, alpha=None, linewidths=None, verts=None, edgecolors=None, hold=None, data=None, **kwargs)Make a scatter plot of `x` vs `y`Marker size is scaled by `s` and marker color is mapped to `c`Parameters----------x, y : array_like, shape (n, )Input datas : scalar or array_like, shape (n, ), optionalsize in points^2.  Default is `rcParams['lines.markersize'] ** 2`. c : color, sequence, or sequence of color, optional, default: 'b'      `c` can be a single color format string, or a sequence of color    specifications of length `N`, or a sequence of `N` numbers to be   mapped to colors using the `cmap` and `norm` specified via kwargs  (see below). Note that `c` should not be a single numeric RGB or   RGBA sequence because that is indistinguishable from an array of   values to be colormapped.  `c` can be a 2-D array in which the     rows are RGB or RGBA, however, including the case of a single      row to specify the same color for all points.marker : `~matplotlib.markers.MarkerStyle`, optional, default: 'o'     See `~matplotlib.markers` for more information on the different    styles of markers scatter supports. `marker` can be eitheran instance of the class or the text shorthand for a particular    marker.cmap : `~matplotlib.colors.Colormap`, optional, default: NoneA `~matplotlib.colors.Colormap` instance or registered name.       `cmap` is only used if `c` is an array of floats. If None,defaults to rc `image.cmap`.norm : `~matplotlib.colors.Normalize`, optional, default: NoneA `~matplotlib.colors.Normalize` instance is used to scaleluminance data to 0, 1. `norm` is only used if `c` is an array of  floats. If `None`, use the default :func:`normalize`.vmin, vmax : scalar, optional, default: None`vmin` and `vmax` are used in conjunction with `norm` to normalize luminance data.  If either are `None`, the min and max of the      color array is used.  Note if you pass a `norm` instance, your     settings for `vmin` and `vmax` will be ignored.alpha : scalar, optional, default: NoneThe alpha blending value, between 0 (transparent) and 1 (opaque)   linewidths : scalar or array_like, optional, default: NoneIf None, defaults to (lines.linewidth,).verts : sequence of (x, y), optionalIf `marker` is None, these vertices will be used toconstruct the marker.  The center of the marker is locatedat (0,0) in normalized units.  The overall marker is rescaled      by ``s``.edgecolors : color or sequence of color, optional, default: None       If None, defaults to 'face'If 'face', the edge color will always be the same asthe face color.If it is 'none', the patch boundary will notbe drawn.For non-filled markers, the `edgecolors` kwargis ignored and forced to 'face' internally.Returns-------paths : `~matplotlib.collections.PathCollection`Other parameters----------------kwargs : `~matplotlib.collections.Collection` propertiesSee Also--------plot : to plot scatter plots when markers are identical in size and    colorNotes-----* The `plot` function will be faster for scatterplots where markers    don't vary in size or color.* Any or all of `x`, `y`, `s`, and `c` may be masked arrays, in which  case all masks will be combined and only unmasked points will be     plotted.Fundamentally, scatter works with 1-D arrays; `x`, `y`, `s`, and `c` may be input as 2-D arrays, but within scatter they will beflattened. The exception is `c`, which will be flattened only if its size matches the size of `x` and `y`.

我们可以看到参数比较多,平时主要用到的就是大小、颜色、样式这三个参数

s:形状的大小,默认 20,也可以是个数组,数组每个参数为对应点的大小,数值越大对应的图中的点越大。
c:形状的颜色,"b":blue   "g":green    "r":red   "c":cyan(蓝绿色,青色)  "m":magenta(洋红色,品红色) "y":yellow "k":black  "w":white
marker:常见的形状有如下
".":点                   ",":像素点           "o":圆形
"v":朝下三角形   "^":朝上三角形   "<":朝左三角形   ">":朝右三角形
"s":正方形           "p":五边星          "*":星型
"h":1号六角形     "H":2号六角形

"+":+号标记      "x":x号标记
"D":菱形              "d":小型菱形 
"|":垂直线形         "_":水平线形

我们来看几个示例(在一张图显示了)

import matplotlib.pyplot as plt
import numpy as np
import pandas as pdx=np.array([3,5])
y=np.array([7,8])x1=np.random.randint(10,size=(25,))
y1=np.random.randint(10,size=(25,))plt.scatter(x,y,c='r')
plt.scatter(x1,y1,s=100,c='b',marker='*')#使用pandas来读取
x2=[]
y2=[]
rdata=pd.read_table('1.txt',header=None)
for i in range(len(rdata[0])):x2.append(rdata[0][i].split(',')[0])y2.append(rdata[0][i].split(',')[1])plt.scatter(x2,y2,s=200,c='g',marker='o')
plt.show()

其中文档1.txt内容如下(上面图中的4个绿色大点)

5,6
7,9
3,4
2,7

Python画图之散点图(plt.scatter)相关推荐

  1. 数字的可视化:python画图之散点图sactter函数详解

    最近开始学习Python编程,遇到scatter函数,感觉里面的参数不知道什么意思于是查资料,最后总结如下: 1.scatter函数原型 2.其中散点的形状参数marker如下: 3.其中颜色参数c如 ...

  2. python色卡_python matplotlib:plt.scatter() 大小和颜色参数详解

    语法 plt.scatter(x, y, s=20, c='b') 大小s默认为20,s=0时点不显示:颜色c默认为蓝色. 为每一个点指定大小和颜色 有时我们需要为每一个点指定大小和方向,以区分不同的 ...

  3. python画图(散点图,折线图)

    判断小数点几位 先将浮点数转化为字符串,然后截取小数点右边的字符,在使用len函数. x=3.25 len(str(x).split(".")[1]) 绘制散点图 #需导入要用到的 ...

  4. Python画图-中使用plt生成的图的legend,设置字体大小

    1 要点 用legend(fontsize=)方法是无效的,需要添加plt的属性参数 plt.rcParams.update({'font.size':18}) plt.rcParams.update ...

  5. Python数据可视化的例子——散点图(scatter)

    (关系型数据的可视化) 散点图用于发现两个数值变量之间的关系 如果需要研究两个数值型变量之间是否存在某种关系,例如正向的线性关系,或者是趋势性的非线性关系,那么散点图将是最佳的选择. 1.matplo ...

  6. python画图-Python基础-画图:matplotlib

    Python画图主要用到matplotlib这个库.具体来说是pylab和pyplot这两个子库.这两个库可以满足基本的画图需求. pylab神器:pylab.rcParams.update(para ...

  7. python画图的模块_python强大的绘图模块matplotlib示例讲解

    Matplotlib 是 Python 的绘图库.作为程序员,经常需要进行绘图,在我自己的工作中,如果需要绘图,一般都是将数据导入到excel中,然后通过excel生成图表,这样操作起来还是比较繁琐的 ...

  8. matplotlib  plt.scatter

    https://www.cnblogs.com/lfri/p/12248629.html matplotlib  plt.scatter 作用:画散点图 plt.scatter() 参数如下: x,y ...

  9. python画图实战_python实战学习之matplotlib绘图续

    学习完matplotlib绘图可以设置的属性,还需要学习一下除了折线图以外其他类型的图如直方图,条形图,散点图等,matplotlib还支持更多的图,具体细节可以参考官方文档:https://matp ...

  10. python中的散点图还可以这么画

    大家平时为了直观地显示数据的分布情况,在画散点图的时候,简单地把数据点用圆点标出来,像这样: 这样: 还有这样: 然而今天我想给大家展示的散点图,或许没有那么直观地反映数据的分布情况,不够实用,但是真 ...

最新文章

  1. C# try与finally(WinForm、Asp.Net)
  2. 思科:四分之三的物联网项目将以失败告终
  3. 信息系统项目管理知识--项目管理一般知识
  4. 艾伟:WCF从理论到实践(2):决战紫禁之巅
  5. 在Ubuntu上安装Sublime Text 3
  6. python廖老师_Python3.5-20190518-廖老师-自我笔记-面向对象
  7. ppt使用记录之添加带圈的20以内的数字编号
  8. asp人脸识别,asp刷脸识别接口代码,微信公众号人脸识别代码
  9. Rust 从入门到精通12-集合
  10. C#解析mobi格式的文档
  11. 音乐节奏提取matlab,音乐旋律提取算法 附可执行demo
  12. 博士申请 | 英国格拉斯哥大学赵德宗教授课题组招收无人驾驶方向全奖博士生...
  13. 平面一般力系最多可以求解_利用平面任意力系的平衡方程最多可求解几个未知量(  )。...
  14. 胡灵 c语言,C语言门真相
  15. 智慧书-永恒的处世经典格言:201-240
  16. C++ Qt 高分屏处理心得
  17. Nginx之父被抓!员工“接私活儿”到底合不合法?
  18. I/O流(包括操作系统与内核,用户空间),I/O工作原理,Java I/O流的设计及Java IO系统
  19. AL11的目录配置和open dataset访问共享文件的权限
  20. vba抓取html文件数据,VBA抓取PDF数据

热门文章

  1. python无法启动此程序因为_python报错:无法启动此程序,因为计算机中丢失
  2. python实现自动登录网页用户名密码_Python使用selenium实现网页用户名 密码 验证码自动登录功能...
  3. linux scp 非22端口,[ssh scp sftp] 连接远程ssh非22端口的服务器方法
  4. c语言编程多分支,C语言编程(练习4:分支和跳转 )
  5. c++ 11 中for循环新增的用法(基于范围的for循环)
  6. 优雅的断开连接--shutdown()
  7. IMPLEMENT_DYNCREATE(CFileView, CView)
  8. mysql修改、删除数据记录
  9. 圈圈教你玩USB(第二版) 笔记
  10. c语言上机题库大一,C语言上机题库(一).doc