如何使用颜色图为散点图设置动画

时间:2018-07-05 14:56:46

标签: python animation colormap

这是使用colormap绘制散点图的python代码。

import scipy.io as sio
import matplotlib.pyplot as plt
import numpy as np

fig=plt.figure(1, figsize=(12,8), frameon=False)
plt.axis('off')
data=sio.loadmat(‘FILE.mat’)

x_357=data['x_357']
y_357=data['y_357']
m_357=data['m_357']*100
sizes=100+0*np.linspace(1,10,len(x_357))
plt.scatter(x_357, y_357, c=m_357, s=sizes, alpha=1, cmap='bwr')
bounds=[5,6,7,8,9,10,11,12,13,14,15]
plt.colorbar(orientation=’horizontal’, boundaries=bounds, ticks=bounds, label=’cm/s’)

下面的代码是对绘图进行动画处理的代码。但是我似乎无法用颜色图对其进行动画处理。

import scipy.io as sio
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.animation import FuncAnimation

fig, ax=plt.subplots(1, figsize=(12,8), frameon=False)
plt.axis(‘off’)
data=sio.loadmat('FILE.mat')

x_357=data['x_357']
y_357=data['y_357']
c_357=data['m_357']*100
xdata, ydata= [], []
ln, =plt.plot([], [],'ro', animated=True)

def init():
    ax.set_xlim(-1050,50)
    ax.set_ylim(-50,500)
    return ln,

def animate(frame):
    xdata.append(x_357[frame])
    ydata.append(y_357[frame])
    ln.set_data(xdata, ydata)
    return ln,

ani= FuncAnimation(fig, animate, frames=range(163), init_func=init, 
blit=True)

plt.show()

如何将颜色图添加到动画中。

0 个答案:

没有答案