使用交互式ipywidget进行时间序列图

时间:2020-11-05 14:48:10

标签: python pandas matplotlib ipywidgets

我可以使用@ ipywidgets.interact设置演示图

import ipywidgets as widgets
import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots(figsize=(6, 4))
ax.set_ylim([-4, 4])
ax.grid(True)
 
x = np.linspace(0, 2 * np.pi, 100)
 
 
def my_sine(x, w, amp, phi):
    """
    Return a sine for x with angular frequeny w and amplitude amp.
    """
    return amp*np.sin(w * (x-phi))
 
 
@widgets.interact(w=(0, 10, 1), amp=(0, 4, .1), phi=(0, 2*np.pi+0.01, 0.01))
def update(w = 1.0, amp=1, phi=0):
    """Remove old lines from plot and plot new one"""
    [l.remove() for l in ax.lines]
    ax.plot(x, my_sine(x, w, amp, phi), color='C0')

但是,我想使用交互工具,尤其是缩放工具来进行时间序列可视化。而且我不知道如何将下面的简单df.plot包装到小部件函数中

cols_plot = ['A', 'B', 'C']
axes = df[cols_plot].plot(linewidth=2.5, fontsize='16', figsize=(22, 18), subplots=True)
for ax in axes:
    ax.set_xlabel('Timestamp',fontsize=20)

0 个答案:

没有答案
相关问题