我在使用mpld3在浏览器中查看动画图形时遇到问题。有什么关于我做错什么的提示吗?如果我能想出如何把它转换成html,这样我就能把它嵌入我的网站,那就更好了。在
import matplotlib.pyplot as plt
import mpld3
import matplotlib.animation as animation
from matplotlib import style
import pandas as pd
import matplotlib.dates
from mpldatacursor import datacursor
style.use('fivethirtyeight')
fig = plt.figure()
ax = plt.subplot2grid((1,1), (0,0))
dateparse = lambda x: pd.datetime.strptime(x,
'%m/%d/%y %I:%M:%S %p')
def animate (i):
df = pd.read_csv('arp.csv',
index_col='Number',
parse_dates=['Date'],
date_parser=dateparse,
delimiter =',')
e = i+1440
df_tfvolts = df.iloc[i:e, 1]
df_tftime = df.iloc[i:e, 0]
b = matplotlib.dates.date2num(df.iloc[i:e, 0])
ax.clear()
ax.plot(df_tftime, df_tfvolts, 'r')
ax.fill_between(b, df_tfvolts, facecolor='r', alpha =0.3)
for label in ax.xaxis.get_ticklabels():
label.set_rotation(30)
plt.title('Lghtbug 7')
plt.subplots_adjust(top=0.893,
bottom=0.2,
right=0.962,
left=0.11)
plt.xlabel('Date')
plt.ylabel('Volt')
datacursor(hover=True, bbox = None, point_labels = None,
draggable = True)
ani = animation.FuncAnimation (fig,
animate,
interval=10)
mpld3.show()
如果你真的想制作一个动画,你可以从Bokeh库中看看the surface3d example(代码是here)。
否则,如果您只想逐步看到数据发生的情况,我建议您使用滑块。在mpld3中应该有一种方法可以做到这一点,但是demo不起作用。。。你可以和博凯核对一下this other example。在
相关问题 更多 >
编程相关推荐