我正在尝试做这样的事情来仔细查看我的数据:
目前在 Jupyter/iPython 中动态更新绘图的正确方法是什么? https://stackoverflow.com/questions/34486642/what-is-the-currently-correct-way-to-dynamically-update-plots-in-jupyter-ipython
或者在这里:https://nbviewer.jupyter.org/gist/branning/c8e63ce81be0391260b1 https://nbviewer.jupyter.org/gist/branning/c8e63ce81be0391260b1
这是我的代码:
%matplotlib notebook
from matplotlib import pyplot as plt
import pandas as pd
START = DATA.index[0]
END = DATA.index[-1]
DT = "6H"
DATERANGE = pd.date_range(START, END, freq=DT)
fig, ax = plt.subplots(figsize(8, 6))
since = DATERANGE[0]
for till in DATERANGE[1:]:
data = DATA['SOME_SERIES'].loc[since:till]
if len(data) > 0:
if ax.lines:
ax.lines[0].set_xdata(data.index)
ax.lines[0].set_ydata(data)
else:
ax.plot(data.index, data)
upper, lower = data.min()*0.9, data.max()*1.1
if not (isnan(upper) or isnan(lower)):
ax.set_ylim((data.min()*0.9, data.max()*1.1))
ax.set_xlim((data.index[0], data.index[-1]))
fig.canvas.draw()
time.sleep(2)
since = till
我的问题是,虽然绘图正在更新,但它并没有填充画布(希望我在那里掌握了术语),但只有大约四分之一的大小。
它看起来像这样:
循环时绘图 https://i.stack.imgur.com/ET1In.png
只有当循环结束时,情节才会变得更大:
循环后的绘图 https://i.stack.imgur.com/afMu7.png
上面链接中的确切代码也是如此。
我更新了 jupyter 和 matplotlib,我尝试了Fig.tight_layout(),我还尝试了 %matplotlib Notebook %matplotlib nbagg 但这也没有解决问题。
有人有解决方案吗?
谢谢,
菲利普