我是 JupyterLab 的新手,正在尝试学习。
当我尝试绘制图形时,它在 jupyter notebook 上运行良好,但在 jupyterlab 上没有显示结果。谁能帮我这个?
以下是代码:
import pandas as pd
import pandas_datareader.data as web
import time
# import matplotlib.pyplot as plt
import datetime as dt
import plotly.graph_objects as go
import numpy as np
from matplotlib import style
# from matplotlib.widgets import EllipseSelector
from alpha_vantage.timeseries import TimeSeries
下面是绘图的代码:
def candlestick(df):
fig = go.Figure(data = [go.Candlestick(x = df["Date"], open = df["Open"], high = df["High"], low = df["Low"], close = df["Close"])])
fig.show()
JupyterLab 结果:
Link to the image (JupyterLab)
JupyterNotebook 结果:
Link to the image (Jupyter Notebook)
我已经将 JupyterLab 和 Notebook 都更新到了最新版本。我不知道是什么导致 JupyterLab 停止显示数字。
感谢您阅读我的帖子。帮助将不胜感激。
注*
我没有包括数据读取部分(库存 OHLC 值)。它包含 API key 。给您带来不便,我深表歉意。
另外,这是我关于堆栈溢出的第二篇文章。如果这篇文章写得不好,我很抱歉。如果可能的话,我会努力付出更多。再次感谢您的帮助。
最佳答案
TL;博士:
运行以下命令,然后重新启动您的 jupyter 实验室
jupyter labextension install @jupyterlab/plotly-extension
开始实验室:
jupyter lab
使用以下代码进行测试:
import plotly.graph_objects as go
from alpha_vantage.timeseries import TimeSeries
def candlestick(df):
fig = go.Figure(data = [go.Candlestick(x = df.index, open = df["1. open"], high = df["2. high"], low = df["3. low"], close = df["4. close"])])
fig.show()
# preferable to save your key as an environment variable....
key = # key here
ts = TimeSeries(key = key, output_format = "pandas")
data_av_hist, meta_data_av_hist = ts.get_daily('AAPL')
candlestick(data_av_hist)
更长的解释:
由于此问题与 plotly 而非 matplotlib 有关,因此您不必使用以下“内联魔法”:
%matplotlib inline
每个扩展都必须安装到 jupyter 实验室,您可以使用以下命令查看列表:
jupyter labextension list
有关另一个扩展的更详细说明,请参阅相关问题:
jupyterlab interactive plot
关于pandas - JupyterLab 无花果不显示。它显示空白结果(但在 jupyternotebook 上工作正常),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58408092/