首页 > 解决方案 > 无法在pycharm中使用plotly绘制熊猫数据框数据

问题描述

我正在尝试在 pycharm 中使用 plotly 绘制熊猫数据框数据,但它不起作用。以下是代码片段。

import plotly.plotly as py
import pandas as pd
import numpy as np
import cufflinks as cf

cf.go_offline()

df = pd.DataFrame(np.random.randn(100,4),columns='A B C D'.split())
print(df.head())

df.iplot()

当我在 pycharm 中运行上述代码时,它会抛出错误

plotly.exceptions.PlotlyError: Because you didn't supply a 'file_id' in the call, we're assuming you're trying to snag a figure from a url. You supplied the url, '', we expected it to start with 'https://plot.ly'.
Run help on this function for more information.

不确定这里到底出了什么问题。

谁能帮我这个?

谢谢。

标签: pythonpandasdataframepycharmplotly

解决方案


您的代码原样在 Jupyter Notebook 中运行良好并生成此图

在此处输入图像描述

所以问题归结为如何在 PyCharm 中运行代码。Python 控制台?也许是 IPython?为了情节和iplot()离线运行,我认为你必须在 Jupyter Notebook 中运行这个特定的片段。但是你也可以在 PyCharm 中做到这一点File > New > Jupyter Notebook:

在此处输入图像描述

您可能需要进行一些额外的安装,但这一点也不难。


推荐阅读