鍍金池/ 問答/數(shù)據(jù)分析&挖掘  Python/ python Matplotlib如何實(shí)現(xiàn)類似分頁(yè)的功能

python Matplotlib如何實(shí)現(xiàn)類似分頁(yè)的功能

需求:假如每天有1000條數(shù)據(jù),1000個(gè)點(diǎn),共有100天,如果把1000 * 100天的數(shù)據(jù)放在一個(gè)view里面,不能直觀的看到數(shù)據(jù)的具體表現(xiàn),有沒有辦法實(shí)現(xiàn)一個(gè)類似的功能,每次看1000條數(shù)據(jù),然后通過點(diǎn)擊看下一頁(yè)的數(shù)據(jù),Matplotlib能實(shí)現(xiàn)這樣的功能嗎。

x = [1,2,3]
day1 = [1,2,3]
day2 = [2,4,6]
......
dayn = [100,200,300]
plt.plot(x,dayn ,color='red')

如何能很好的一天一天的畫圖,每次看到的只是一天的數(shù)據(jù)

回答
編輯回答
墨小白

當(dāng)然可以,可以使用 matplotlib 的滑塊組件。

下面這個(gè)例子,通過拖動(dòng)滑塊顯示不同的圖像

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider

fig, ax = plt.subplots()
plt.subplots_adjust(left=0.25, bottom=0.25)

axindex = plt.axes([0.25, 0.1, 0.65, 0.03], facecolor='lightgoldenrodyellow')
sindex = Slider(axindex, 'Index', 1, 10, valinit=2, valstep=1)

def update(val):
    index = int(sindex.val)
    ax.clear()
    ax.set_xlabel('index={}'.format(index))
    x = np.arange(0, 2*np.pi, 0.01)
    y = np.sin(x * (2 ** index))
    ax.plot(x, y)
    fig.canvas.draw_idle()
sindex.on_changed(update)

update(None)
plt.show()

動(dòng)畫效果圖
圖片描述

如果要輸出報(bào)告,可改用 PDF 分頁(yè)。

2017年11月22日 07:58