广告
返回顶部
首页 > 资讯 > 后端开发 > Python >Python画图之散点图(plt.scatter)
  • 302
分享到

Python画图之散点图(plt.scatter)

点状图散点图scatter 2023-10-05 22:10:17 302人浏览 安东尼

Python 官方文档:入门教程 => 点击学习

摘要

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

        散点图的应用很广泛,以前介绍过很多画图方法: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 data    s : Scalar or array_like, shape (n, ), optional        size 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 either        an instance of the class or the text shorthand for a particular            marker.    cmap : `~matplotlib.colors.Colormap`, optional, default: None        A `~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: None        A `~matplotlib.colors.Normalize` instance is used to scale        luminance 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: None        The alpha blending value, between 0 (transparent) and 1 (opaque)       linewidths : scalar or array_like, optional, default: None        If None, defaults to (lines.linewidth,).    verts : sequence of (x, y), optional        If `marker` is None, these vertices will be used to        construct the marker.  The center of the marker is located        at (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 as        the face color.        If it is 'none', the patch boundary will not        be drawn.        For non-filled markers, the `edgecolors` kwarg        is ignored and forced to 'face' internally.    Returns    -------    paths : `~matplotlib.collections.PathCollection`    Other parameters    ----------------    kwargs : `~matplotlib.collections.Collection` properties    See Also    --------    plot : to plot scatter plots when markers are identical in size and            color    Notes    -----    * 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 be      flattened. 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 pltimport numpy as npimport 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

来源地址:https://blog.csdn.net/weixin_41896770/article/details/126876059

--结束END--

本文标题: Python画图之散点图(plt.scatter)

本文链接: https://www.lsjlt.com/news/423904.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Python画图之散点图(plt.scatter)
            散点图的应用很广泛,以前介绍过很多画图方法:Python画图(直方图、多张子图、二维图形、三维图形以及图中图),漏掉了这个,现在补上,用法很简单,我们可以help(plt.scatter)看下它的用法: Help on fu...
    99+
    2023-10-05
    点状图 散点图 scatter
  • python利用scatter绘画散点图
    scatter绘画散点图代码如下: import matplotlib.pyplot  as plt plt.scatter(x,y,                 s = 20 ...
    99+
    2022-11-11
  • python画时间序列散点图
    在运维管理中,经常遇到时间序列的数据,比如网卡流量、在线用户数、并发连接数,等等。用散点图可以直观的查看数据的分布情况。 matplotlib模块的pyplot有画散点图的函数,但是该函数要求x轴是数字类型。pandas的plot函数里,散...
    99+
    2023-01-31
    序列 时间 python
  • matplotlib散点图怎么画
    matplotlib画散点图的步骤:1、导入必要的库;2、创建数据,可以生成一些随机数据;3、使用“plt.scatter()”函数创建散点图,设置颜色、大小、透明度等属性;4、使用“plt.xlabel()”和“plt.ylabel()”...
    99+
    2023-12-09
    Matplotlib
  • python 离散点图画法的实现
    目录基础代码改进再次改进:又次改进:改进:----加准确率基础代码 pred_y = test_output.data.numpy() pred_y = pred_y.flatten...
    99+
    2022-11-13
  • python怎么利用scatter绘画散点图
    这篇文章主要介绍了python怎么利用scatter绘画散点图的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇python怎么利用scatter绘画散点图文章都会有所收获,下面我们一起来看看吧。scatter绘画...
    99+
    2023-07-02
  • python matplotlib库绘图实战之绘制散点图
    目录一.导入库二.设置文字三.设置坐标轴参数四.绘制点五.对点的继续处理1.自定义颜色2.颜色映射补充1补充2补充3总结一.导入库 import matplotlib.pyplot ...
    99+
    2022-11-11
  • matlab三维散点图如何画
    在MATLAB中,可以使用scatter3函数绘制三维散点图。语法:scatter3(x, y, z)scatter3(x, y, ...
    99+
    2023-09-13
    matlab
  • Python Matplotlib数据可视化绘图之(三)————散点图
    文章目录 前言一、所用到的模块二、单一颜色的普通不分组散点图1.示例数据如下2.代码如下2.1 代码如下(示例):2.1.1 Case1: 三、多种颜色的普通不分组散点图1....
    99+
    2023-10-26
    matplotlib python 开发语言 pycharm numpy
  • python 线性拟合图、散点图
    散点图线性拟合 from scipy import statsimport numpy as npimport matplotlib.pyplot as plt#数据生成x = np.linspace...
    99+
    2023-09-27
    python matplotlib 回归
  • R语言数据可视化包ggplot2画图之散点图的基本画法
    目录前言下面以一个简单的例子引入:首先介绍第一类常用的图像类型:散点图 给原始数据加上分类标签:按z列分类以不同的颜色在图中画出散点图:按z列分类以不同的形状在图中画出散点...
    99+
    2022-11-13
    ggplot2绘制散点图 r语言ggplot2作图 r绘制散点图
  • matlab中如何画高维散点图
    在MATLAB中,可以使用`scatter3`函数来绘制三维散点图。对于高维散点图,可以使用降维方法先将数据降到三维,然后再使用`s...
    99+
    2023-09-13
    matlab
  • python scatter绘制散点图
    目录参数 s参数markermarker属性参数cmapvmin,vmax,norm散点亮度设置, alpha透明度用法: matplotlib.pyplot.scatter(x, ...
    99+
    2022-11-11
  • python散点图的绘制
    目录一、二维散点图的绘制1.采用pandas.plotting.scatter_matrix函数绘制2. 采用seaborn进行绘制二、 三维散点图绘制一、二维散点图的绘制 1.采用...
    99+
    2022-11-13
  • Python数据分析之 Matplotlib 散点图绘制
    前言: 散点图,又称散点分布图,是使用多个坐标点的分布反映数据点分布规律、数据关联关系的图表,Matplotlib 中可以通过以下方式绘制散点图: 使用plt.plot方法: 在上篇...
    99+
    2022-11-11
  • chatgpt赋能python:Python散点图介绍:如何用Python绘制散点图?
    Python散点图介绍:如何用Python绘制散点图? Python是一门流行的编程语言,用于解决各种问题和编写各种应用程序。其中,数据可视化是Python应用程序中非常重要的组成部分。散点图是最常用...
    99+
    2023-10-07
    python chatgpt 信息可视化 计算机
  • python散点图怎么绘制
    这篇“python散点图怎么绘制”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇“python散点图怎么绘制”文章吧。一、二维散...
    99+
    2023-06-29
  • Python绘制散点图之可视化神器pyecharts
    目录散点图什么是散点图?散点图有什么用处?散点图的基本构成要素散点图模板系列简单散点图多维数据散点图散点图显示分割线散点图凸出大小(二维) 3D散点图展示动态涟漪散点图箭头...
    99+
    2022-11-11
  • python使用seaborn绘图直方图displot,密度图,散点图
    目录一、直方图distplot()二、密度图2.1 单个样本数据分布密度图一、直方图distplot() import numpy as np import seaborn as ...
    99+
    2022-11-11
  • 怎么用Python绘制散点图
    这篇文章主要讲解了“怎么用Python绘制散点图”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“怎么用Python绘制散点图”吧!少废话,直接上代码 import matp...
    99+
    2023-06-29
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作