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)

参数(Parameters)说明:

x,y:array_like,shape(n,)

输入数据

s:标量或array_like,shape(n,),可选

大小以点数^ 2。默认是`rcParams ['lines.markersize'] ** 2`。

c:颜色,顺序或颜色顺序,可选,默认:'b'

`c`可以是单个颜色格式的字符串,也可以是一系列颜色

规范的长度为`N`,或一系列`N`数字

使用通过kwargs指定的`cmap`和`norm`映射到颜色

(见下文)。请注意,`c`不应该是单个数字RGB或

RGBA序列,因为这与数组无法区分

值将被彩色映射。 `c`可以是一个二维数组,其中的

行是RGB或RGBA,但是,包括单个的情况

行为所有点指定相同的颜色。

marker:`〜matplotlib.markers.MarkerStyle`,可选,默认值:'o'

请参阅`〜matplotlib.markers`以获取有关不同的更多信息

标记分散支持的样式。 `marker`可以是

该类的实例或特定文本的简写

标记。

cmap:`〜matplotlib.colors.Colormap`,可选,默认:无

一个`〜matplotlib.colors.Colormap`实例或注册名称。

`cmap`仅在`c`是浮点数组时使用。如果没有,

默认为rc`image.cmap`。

norm:`〜matplotlib.colors.Normalize`,可选,默认:无

`〜matplotlib.colors.Normalize`实例用于缩放

亮度数据为0,1。`norm`只有在`c`是一个数组时才被使用

彩车。如果`None',则使用默认值:func:`normalize`。

vmin,vmax:标量,可选,默认值:无

`vmin`和`vmax`与`norm`结合使用来标准化

亮度数据。如果其中任何一个都是`无',那么最小和最大的

使用颜色数组。请注意,如果你通过一个“规范”实例,你的

`vmin`和`vmax`的设置将被忽略。

alpha:标量,可选,默认值:无

alpha混合值,介于0(透明)和1(不透明)之间,

linewidths:标量或array_like,可选,默认值:无

如果无,则默认为(lines.linewidth,)。

verts:(x,y)的序列,可选

如果`marker`为None,这些顶点将用于

构建标记。标记的中心位于

在(0,0)为标准化单位。整体标记重新调整

由``s``完成。

edgecolors :颜色或颜色顺序,可选,默认值:无

如果无,则默认为'face'

如果'face',边缘颜色将永远是相同的

脸色。

如果它是'none',补丁边界不会

被画下来。

对于未填充的标记,“edgecolors”kwarg

被忽视并被迫在内部“面对”。

简单点绘制

按到原点的距离增大点的大小

x = [0,2,4,6,8,10]

y = [0]*len(x)

s = [20*4**n for n in range(len(x))]

plt.scatter(x,y,s=s)

plt.show()

image.png

x = [0,2,4,6,8,10]

y = [0]*len(x)

s = [20*2**n for n in range(len(x))]

plt.scatter(x,y,s=s)

plt.show()

image.png

import numpy as np

import matplotlib.pyplot as plt

fig=plt.figure(figsize=(8,6))

#Generating a Gaussion dataset:

#creating random vectors from the multivariate normal distribution

#given mean and covariance

mu_vec1=np.array([0,0])

cov_mat1=np.array([[1,0],[0,1]])

X=np.random.multivariate_normal(mu_vec1,cov_mat1,500)

R=X**2

R_sum=R.sum(axis=1)

plt.scatter(X[:,0],X[:,1],color='green',marker='o',

s=32.*R_sum,edgecolor='black',alpha=0.5)

plt.show()

image.png

散点绘制

from matplotlib import pyplot as plt

import numpy as np

# Generating a Gaussion dTset:

#Creating random vectors from the multivaritate normal distribution

#givem mean and covariance

mu_vecl = np.array([0, 0])

cov_matl = np.array([[2,0],[0,2]])

x1_samples = np.random.multivariate_normal(mu_vecl, cov_matl,100)

x2_samples = np.random.multivariate_normal(mu_vecl+0.2, cov_matl +0.2, 100)

x3_samples = np.random.multivariate_normal(mu_vecl+0.4, cov_matl +0.4, 100)

plt.figure(figsize = (8, 6))

plt.scatter(x1_samples[:,0], x1_samples[:, 1], marker='x',

color = 'blue', alpha=0.7, label = 'x1 samples')

plt.scatter(x2_samples[:,0], x1_samples[:,1], marker='o',

color ='green', alpha=0.7, label = 'x2 samples')

plt.scatter(x3_samples[:,0], x1_samples[:,1], marker='^',

color ='red', alpha=0.7, label = 'x3 samples')

plt.title('Basic scatter plot')

plt.ylabel('variable X')

plt.xlabel('Variable Y')

plt.legend(loc = 'upper right')

plt.show()

import matplotlib.pyplot as plt

fig,ax = plt.subplots()

ax.plot([0],[0], marker="o", markersize=10)

ax.plot([0.07,0.93],[0,0], linewidth=10)

ax.scatter([1],[0], s=100)

ax.plot([0],[1], marker="o", markersize=22)

ax.plot([0.14,0.86],[1,1], linewidth=22)

ax.scatter([1],[1], s=22**2)

plt.show()

![image.png](http://upload-images.jianshu.io/upload_images/8730384-8d27a5015b37ee97.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

import matplotlib.pyplot as plt

for dpi in [72,100,144]:

fig,ax = plt.subplots(figsize=(1.5,2), dpi=dpi)

ax.set_title("fig.dpi={}".format(dpi))

ax.set_ylim(-3,3)

ax.set_xlim(-2,2)

ax.scatter([0],[1], s=10**2,

marker="s", linewidth=0, label="100 points^2")

ax.scatter([1],[1], s=(10*72./fig.dpi)**2,

marker="s", linewidth=0, label="100 pixels^2")

ax.legend(loc=8,framealpha=1, fontsize=8)

fig.savefig("fig{}.png".format(dpi), bbox_inches="tight")

plt.show()

image.png

import matplotlib.pyplot as plt

for dpi in [72,100,144]:

fig,ax = plt.subplots(figsize=(1.5,2), dpi=dpi)

ax.set_title("fig.dpi={}".format(dpi))

ax.set_ylim(-3,3)

ax.set_xlim(-2,2)

ax.scatter([0],[1], s=10**2,

marker="s", linewidth=0, label="100 points^2")

ax.scatter([1],[1], s=(10*72./fig.dpi)**2,

marker="s", linewidth=0, label="100 pixels^2")

ax.legend(loc=8,framealpha=1, fontsize=8)

fig.savefig("fig{}.png".format(dpi), bbox_inches="tight")

plt.show()

image.png

import numpy as np

import matplotlib.pyplot as plt

x1 = np.random.randn(20)

x2 = np.random.randn(20)

plt.figure(1)

# you can specify the marker size two ways directly:

plt.plot(x1, 'bo', markersize=20) # blue circle with size 10

plt.plot(x2, 'ro', ms=10,) # ms is just an alias for markersize

plt.show()

image.png

plt.scatter(2, 1, s=4000, c='r')

plt.scatter(2, 1, s=1000 ,c='b')

plt.scatter(2, 1, s=10, c='g')

image.png

带标签点绘制

import matplotlib.pyplot as plt

x_coords = [0.13, 0.22, 0.39, 0.59, 0.68, 0.74,0.93]

y_coords = [0.75, 0.34, 0.44, 0.52, 0.80, 0.25,0.55]

fig = plt.figure(figsize = (8,5))

plt.scatter(x_coords, y_coords, marker = 's', s = 50)

for x, y in zip(x_coords, y_coords):

plt.annotate('(%s,%s)'%(x,y), xy=(x,y),xytext = (0, -10), textcoords = 'offset points',ha = 'center', va = 'top')

plt.xlim([0,1])

plt.ylim([0,1])

plt.show()

image.png

用曲线把样本分成两类

# 2-category classfication with random 2D-sample data

# from a multivariate normal distribution

import numpy as np

from matplotlib import pyplot as plt

def decision_boundary(x_1):

"""Calculates the x_2 value for plotting the decision boundary."""

return 4 - np.sqrt(-x_1**2 + 4*x_1 + 6 + np.log(16))

# Generating a gaussion dataset:

# creating random vectors from the multivariate normal distribution

# given mean and covariance

mu_vec1 = np.array([0,0])

cov_mat1 = np.array([[2,0],[0,2]])

x1_samples = np.random.multivariate_normal(mu_vec1, cov_mat1,100)

mu_vec1 = mu_vec1.reshape(1,2).T # TO 1-COL VECTOR

mu_vec2 = np.array([1,2])

cov_mat2 = np.array([[1,0],[0,1]])

x2_samples = np.random.multivariate_normal(mu_vec2, cov_mat2, 100)

mu_vec2 = mu_vec2.reshape(1,2).T # to 2-col vector

# Main scatter plot and plot annotation

f, ax = plt.subplots(figsize = (7, 7))

ax.scatter(x1_samples[:, 0], x1_samples[:,1], marker = 'o',color = 'green', s=40)

ax.scatter(x2_samples[:, 0], x2_samples[:,1], marker = '^',color = 'blue', s =40)

plt.legend(['Class1 (w1)', 'Class2 (w2)'], loc = 'upper right')

plt.title('Densities of 2 classes with 25 bivariate random patterns each')

plt.ylabel('x2')

plt.xlabel('x1')

ftext = 'p(x|w1) -N(mu1=(0,0)^t, cov1 = I)\np.(x|w2) -N(mu2 = (1, 1)^t), cov2 =I'

plt.figtext(.15,.8, ftext, fontsize = 11, ha ='left')

#Adding decision boundary to plot

x_1 = np.arange(-5, 5, 0.1)

bound = decision_boundary(x_1)

plt.plot(x_1, bound, 'r--', lw = 3)

x_vec = np.linspace(*ax.get_xlim())

x_1 = np.arange(0, 100, 0.05)

plt.show()

image.png

直线划分

# 2-category classfication with random 2D-sample data

# from a multivariate normal distribution

import numpy as np

from matplotlib import pyplot as plt

def decision_boundary(x_1):

"""Calculates the x_2 value for plotting the decision boundary."""

# return 4 - np.sqrt(-x_1**2 + 4*x_1 + 6 + np.log(16))

return -x_1 + 1

# Generating a gaussion dataset:

# creating random vectors from the multivariate normal distribution

# given mean and covariance

mu_vec1 = np.array([0,0])

cov_mat1 = np.array([[2,0],[0,2]])

x1_samples = np.random.multivariate_normal(mu_vec1, cov_mat1,100)

mu_vec1 = mu_vec1.reshape(1,2).T # TO 1-COL VECTOR

mu_vec2 = np.array([1,2])

cov_mat2 = np.array([[1,0],[0,1]])

x2_samples = np.random.multivariate_normal(mu_vec2, cov_mat2, 100)

mu_vec2 = mu_vec2.reshape(1,2).T # to 2-col vector

# Main scatter plot and plot annotation

f, ax = plt.subplots(figsize = (7, 7))

ax.scatter(x1_samples[:, 0], x1_samples[:,1], marker = 'o',color = 'green', s=40)

ax.scatter(x2_samples[:, 0], x2_samples[:,1], marker = '^',color = 'blue', s =40)

plt.legend(['Class1 (w1)', 'Class2 (w2)'], loc = 'upper right')

plt.title('Densities of 2 classes with 25 bivariate random patterns each')

plt.ylabel('x2')

plt.xlabel('x1')

ftext = 'p(x|w1) -N(mu1=(0,0)^t, cov1 = I)\np.(x|w2) -N(mu2 = (1, 1)^t), cov2 =I'

plt.figtext(.15,.8, ftext, fontsize = 11, ha ='left')

#Adding decision boundary to plot

x_1 = np.arange(-5, 5, 0.1)

bound = decision_boundary(x_1)

plt.plot(x_1, bound, 'r--', lw = 3)

x_vec = np.linspace(*ax.get_xlim())

x_1 = np.arange(0, 100, 0.05)

plt.show()

image.png

python scatter函数_Matplotlib之scatter()函数相关推荐

  1. scatter函数_matplotlib.pyplot常用函数scatter讲解大全(三)

    前言 这篇文章再来总结一个常用画图函数scatter-散点图. 参数 常用参数 示例 import matplotlib.pyplot as plt import numpy as np#导入需要的包 ...

  2. python中imshow函数_Matplotlib库imshow函数

    Matplotlib是Python最著名的2D绘图库,该库仿造Matlab提供了一整套相似的绘图函数,用于绘图和绘表,强大的数据可视化工具和做图库,适合交互式绘图,图形美观. imshow:热图(he ...

  3. R语言ggplot2可视化散点图(scatter plot)、aes函数中的fill参数为连续变量、使用scale_fill_distiller函数自定义指定连续变量的颜色填充方案

    R语言ggplot2可视化散点图(scatter plot).aes函数中的fill参数为连续变量.使用scale_fill_distiller函数自定义指定连续变量的颜色填充方案 目录

  4. python pso_利用python实现PSO算法优化二元函数

    python实现PSO算法优化二元函数,具体代码如下所示: import numpy as np import random import matplotlib.pyplot as plt from ...

  5. Python+NetworkX画图的nx.draw_networkx(函数详解)

    Python+NetworkX画图的nx.draw_networkx函数详解 Python+NetworkX画图的nx.draw_networkx(函数详解) Python+NetworkX画图的nx ...

  6. python二元函数如何编写_利用python实现PSO算法优化二元函数

    python实现PSO算法优化二元函数,具体代码如下所示: import numpy as np import random import matplotlib.pyplot as plt from ...

  7. python基础---元组、字典、函数、文件、异常

    文章目录 python基础---元组.字典.函数.文件.异常 Tuple(元组) 常用操作 dict(字典) 函数 文件 异常 python基础-元组.字典.函数.文件.异常 Tuple(元组) tu ...

  8. 在python中使用关键字define定义函数_python自定义函数def的应用详解

    这里是三岁,来和大家唠唠自定义函数,这一个神奇的东西,带大家白话玩转自定义函数 自定义函数,编程里面的精髓! def 自定义函数的必要函数:def 使用方法:def 函数名(参数1,参数2,参数-): ...

  9. python函数的用法详解(作用、定义、调用、函数参数、函数返回值、函数说明文档、函数嵌套使用)

    1. 函数的作⽤ 函数就是将⼀段具有独⽴功能的代码块整合到⼀个整体并命名,在需要的位置调⽤这个名称即可完成对应的需求. 函数在开发过程中,可以更⾼效的实现代码重⽤. 2. 函数的使⽤步骤 2.1 定义 ...

最新文章

  1. 复习es6-解构赋值+字符串的扩展
  2. 美团面试失败(Java开发)
  3. 01月26日【Python3 基础知识】
  4. Fastjson 1.2.66 版本发布,继续加固安全!
  5. win10系统 ubuntu子系统 进行ndk编译笔记
  6. sklearn 分类(上证指数涨跌预测)
  7. 企业数字化转型解决方案
  8. 2017.9.17 function 思考记录
  9. 机器学习算法-09-深度学习、BP神经网络、Hopfield神经网络、基于数学原理的神经网络、径向基函数RBF(B站一条会说666的咸鱼)
  10. springboot配置错误页面
  11. 在matlab使用矩阵的方法计算DFT
  12. 那些值得吟唱的诗词歌赋
  13. 金融行业比较有名气的公司
  14. 2021年全球拍立得消耗品(胶片和相纸)收入大约205.8百万美元,预计2028年达到291百万美元
  15. springboot手写JDBC面对2000并发量毫无压力
  16. IIS6 + Resin3.1.x 的不爽之处
  17. 科研必备的12个网站
  18. 【技术专题】如何做数据库选型?
  19. 推荐一个C++枚举转字符串的开源项目magic_enum
  20. ferguson博弈_人物介绍!扑克界传奇人物“耶稣”Chris Ferguson

热门文章

  1. 怎么去理解高类聚低耦合这种概念
  2. 关于asterisk做呼叫转接的一点经验记录
  3. 吴恩达 Chatgpt prompt 工程--1.Guidelines
  4. python批量上传文件到服务器_Python脚本06 —— 批量上传图片到七牛服务器
  5. 【农业害虫识别论文一】Crop pest classification based on deep convolutional neural network and transfer learning
  6. 智慧树怎么导入教务系统的课_智慧树——后疫情时代异地直播课堂解决方案
  7. Bootstrap网页切版练习(一) - 响应式交错版
  8. 使用python将excel表格中的A+,A等分数自动转换成百分制分数,并自动保存于excel中
  9. Java海康威视摄像头实时预览视频流保存到指定文件中
  10. 新能源控制器,新能源汽车车载双向OBC,PFC,LLC,V2G 双向 充电桩 电动汽车 车载充电机 充放电机 MATLAB仿真模型