小编典典

假设有一个散点图scat = ax.scatter(…),则可以

改变立场

scat.set_offsets(array)

其中array是N x 2x和y坐标的形状数组。

改变大小

scat.set_sizes(array)

其中array是以点为单位的一维尺寸数组。

改变颜色

scat.set_array(array)

其中array是一维值数组,将对其进行颜色映射。

这是一个使用animation模块的简单示例。

它比必须的要复杂一些,但是这应该为您提供一个做奇特的事情的框架。

(代码编辑于2019年4月以与当前版本兼容。有关旧代码,请参阅修订历史记录)

import matplotlib.pyplot as plt

import matplotlib.animation as animation

import numpy as np

class AnimatedScatter(object):

“”“An animated scatter plot using matplotlib.animations.FuncAnimation.”“”

def init(self, numpoints=50):

self.numpoints = numpoints

self.stream = self.data_stream()

# Setup the figure and axes...

self.fig, self.ax = plt.subplots()

# Then setup FuncAnimation.

self.ani = animation.FuncAnimation(self.fig, self.update, interval=5,

init_func=self.setup_plot, blit=True)

def setup_plot(self):

"""Initial drawing of the scatter plot."""

x, y, s, c = next(self.stream).T

self.scat = self.ax.scatter(x, y, c=c, s=s, vmin=0, vmax=1,

cmap="jet", edgecolor="k")

self.ax.axis([-10, 10, -10, 10])

# For FuncAnimation's sake, we need to return the artist we'll be using

# Note that it expects a sequence of artists, thus the trailing comma.

return self.scat,

def data_stream(self):

"""Generate a random walk (brownian motion). Data is scaled to produce

a soft "flickering" effect."""

xy = (np.random.random((self.numpoints, 2))-0.5)*10

s, c = np.random.random((self.numpoints, 2)).T

while True:

xy += 0.03 * (np.random.random((self.numpoints, 2)) - 0.5)

s += 0.05 * (np.random.random(self.numpoints) - 0.5)

c += 0.02 * (np.random.random(self.numpoints) - 0.5)

yield np.c_[xy[:,0], xy[:,1], s, c]

def update(self, i):

"""Update the scatter plot."""

data = next(self.stream)

# Set x and y data...

self.scat.set_offsets(data[:, :2])

# Set sizes...

self.scat.set_sizes(300 * abs(data[:, 2])**1.5 + 100)

# Set colors..

self.scat.set_array(data[:, 3])

# We need to return the updated artist for FuncAnimation to draw..

# Note that it expects a sequence of artists, thus the trailing comma.

return self.scat,

if name == "main’:

a = AnimatedScatter()

plt.show()

在此处输入图片说明

如果使用OSX并使用OSX后端,则需要在下面的初始化中将更改blit=True为。OSX后端不完全支持blitting。性能会受到影响,但是示例应在禁用blitting的情况下在OSX上正确运行。blit=FalseFuncAnimation

对于一个仅更新颜色的简单示例,请看以下内容:

import matplotlib.pyplot as plt

import numpy as np

import matplotlib.animation as animation

def main():

numframes = 100

numpoints = 10

color_data = np.random.random((numframes, numpoints))

x, y, c = np.random.random((3, numpoints))

fig = plt.figure()

scat = plt.scatter(x, y, c=c, s=100)

ani = animation.FuncAnimation(fig, update_plot, frames=xrange(numframes),

fargs=(color_data, scat))

plt.show()

def update_plot(i, data, scat):

scat.set_array(data[i])

return scat,

main()

2020-02-21

python如何做散点图-Python-如何为散点图制作动画?相关推荐

  1. python能做什么-python能干嘛

    广告关闭 腾讯云双11爆品提前享,精选热门产品助力上云,云服务器首年88元起,买的越多返的越多,最高满返5000元! python有很多优雅有趣的代码写法,同时还很简短,以至于当我刚开始接触这个编程语 ...

  2. python能做什么-Python到底能做什么?

    image 愿码Slogan | 连接每个程序员的故事 愿码愿景 | 打造全学科IT系统免费课程,助力小白用户.初级工程师0成本免费系统学习.低成本进阶,帮助BAT一线资深工程师成长并利用自身优势创造 ...

  3. python能做什么-python能用来做什么?这3大主要用途你一定要知道!(实用)

    这个问题不好回答,因为Python有很多用途. 但是随着时间,我发现有Python主要有以下三大主要应用: Web开发 数据科学:包括机器学习.数据分析和数据可视化 脚本 本文将依次介绍. 作者:YK ...

  4. python可以做什么-Python简直就是万能的,你用Python都做过哪些事?

    Python简直就是万能的,你用Python都做过哪些事? 用网页看各大网站的VIP视频,用python下载? 用Python玩跳一跳,跳到50000分? 过年过节各大亲友群.红包群抢红包还用Pyth ...

  5. python可以做什么-Python是什么?用Python可以做什么?

    Python是一种相当高级的解释性程序设计语言,完成同一个任务C语言可能需要几千行代码 Java要写100行,Python可能只需要20行. 用Python可以做什么?可以做日常任务,比如自动备份你的 ...

  6. python能做什么-Python到底能做什么?它的优点在哪

    Python今天是排名前3的最受欢迎和增长最快的编程语言之一.它是一种多用途,高级别,面向对象,交互式,解释型和对用户非常友好的编程语言. 交互模式是Python shell的一项功能,可为您在控制台 ...

  7. python能做什么-python都能干什么用

    一.Python可以做什么? 1.数据库:Python在数据库方面很优秀,可以和多种数据库进行连接,进行数据处理,从商业型的数据库到开放源码的数据库都提供支持.例如:Oracle, My SQL Se ...

  8. 爬虫python能做什么-Python 爬虫学到什么样就可以找工作了?

    前段时间快要毕业,而我又不想找自己的老本行Java开发了,所以面了很多Python爬虫岗位.因为我在南京上学,所以我一开始只是在南京投了简历,我一共面试了十几家企业,其中只有一家没有给我发offer, ...

  9. python可以用来做什么-Python 学会之后可以用来干嘛的?

    近年来Python在AI和数据分析领域大展拳脚,据Stack Overflow调研报告显示,Python的月活用户已超越了Java.成为第一! Python能玩的东西太多了,今天就说几个比较有趣的: ...

  10. python主要用于做什么-python主要用于哪些方向

    Python的应用范围广,无论是web开发,还是数据抓取,运维测试,都可以用它来实现,下面来具体看一下: Web应用开发 Python经常被用于Web开发.比如,通过mod_wsgi模块,Apache ...

最新文章

  1. VS不显示最近打开的项目
  2. [Google API](1)简介
  3. 金融危机带给我的思考
  4. 《HTML5触摸界面设计与开发》——导读
  5. 深度学习中反向传播得到的损失是一个标量
  6. 201521123014 《Java程序设计》第11周学习总结
  7. 《JavaScript高级程序设计(第四版)》红宝书学习笔记(2)(第四章:变量、作用域与内存)
  8. eemd优缺点_基于EEMD的信号处理方法分析和实现
  9. 移动端机器学习模型压缩也自动化了:腾讯新框架为自家模型加速50%
  10. 51单片机数码管小数点c语言,求助一个51单片机控制的数码管计算器带小数点功能的...
  11. matlab简单分析矩阵乘法——一阶行向量乘一阶列向量
  12. 多线程、多核技术是什么技术?
  13. python 组态_西门子组态WinCC自学入门视频教程资源_48讲
  14. 获评优秀案例!IMG光线追踪技术实现卓越云游戏体验
  15. python跳转下一页_我怎么能跳转到下一页呢
  16. 解决:outlook邮件内容过宽,打印不全
  17. Android UI最佳实践
  18. Myeclipse链接sql server 2005是出现Error while performing database login with the sql2005 driver:
  19. 数据结构与算法(Python)【PKU MOOC】
  20. 概论第6章_正态总体的抽样分布_样本均值的期望与样本方差的期望__方差的期望

热门文章

  1. js 控制展开折叠 div html dom
  2. STL的erase()陷阱-迭代器失效总结
  3. rest项目的基础返回类设计
  4. 使用Struts2防止表单重复提交
  5. log4j文件的配置
  6. 代码之美 - 小函数总结
  7. UICollectionView 简单使用
  8. iOS Block总结
  9. 对集合使用Comparator
  10. jquery为图片添加事件