我在一本朱庇特笔记本上工作,里面有熊猫和熊猫。
我可以创建一个没有问题的图表,但是当我想要添加一个元素(比如Span)时,我想不出如何避免获得显示在笔记本中的第二份图表。
有什么办法可以做到:
此代码演示了以下问题:
# spantest.ipynb
import pandas as pd
import numpy as np
import pandas_bokeh
from bokeh.models import Span
from bokeh.plotting import show
pandas_bokeh.output_notebook()
# Example linechart code from pandas-bokeh docs:
# https://github.com/PatrikHlobil/Pandas-Bokeh#lineplot
np.random.seed(42)
df = pd.DataFrame({"Google": np.random.randn(1000)+0.2,
"Apple": np.random.randn(1000)+0.17},
index=pd.date_range('1/1/2000', periods=1000))
df = df.cumsum()
df = df + 50
fig = df.plot_bokeh(kind="line")
# So far, so good. At this point, I have one chart displayed.
# Now let's say I want to include a Span to indicate some threshold:
span = Span(location=150, dimension='width', line_color='green')
fig.add_layout(span)
show(fig)
# Now I can see the update, but it is displayed as a second copy of the chart. :-(发布于 2021-06-11 14:53:21
找到答案在医生里 (想象一下)。
必须将选项show_figure=False添加到图形创建行,以防止在图形创建中显示该选项:
fig = df.plot_bokeh(kind="line", show_figure=False)然后,当我调用show(fig)时,它只出现一次
我发誓在发帖之前我已经试过了。啊好吧..。
https://stackoverflow.com/questions/67938730
复制相似问题