python Plotly:iplot不能和df.iplot()一起工作,我怎样才能让它工作呢?

gopyfrb3  于 2023-03-11  发布在  Python
关注(0)|答案(2)|浏览(161)
enter code here
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from sklearn import decomposition
from sklearn import datasets
import seaborn as sns
%matplotlib inline
import plotly as py
import plotly.tools as tls
py.offline.init_notebook_mode(connected=True)
from plotly.offline import iplot

df1=pd.DataFrame(np.random.randn(10,3),columns=['A','B','C'])
df1.iplot()

我得到的错误一样'DataFrame'对象没有属性'iplot'我希望有人可以帮助我,提前感谢。

sg3maiej

sg3maiej1#

不需要再用iplot了,只要把Pandas绘图后台设置成plotly,用pd.options.plotting.backend = "plotly",用df.plot()就行了。
下面是使用您的示例的设置:

import pandas as pd
pd.options.plotting.backend = "plotly"

df1=pd.DataFrame(np.random.randn(10,3),columns=['A','B','C'])
df1.plot()

unguejic

unguejic2#

为了补充@vestland提供的已接受答案:如果你正在绘制几个图形,你可能不想使用Plotly作为整个会话的默认后端。
仅对特定地物使用“打印”的步骤:

import pandas as pd

df1 = pd.DataFrame(np.random.randn(10, 3), columns=['A', 'B', 'C'])

df1.plot(backend="plotly")  # Plot using Plotly
df1.plot()  # Plot using the session backend (which is "matplotlib" by default)

相关问题