Plotly: iplot is not working with df.iplot(). How can i make it work?

3.2k views Asked by At
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()

i am getting error like 'DataFrame' object has no attribute 'iplot' i hope some one could help me, thanks in advance.

2

There are 2 answers

3
vestland On BEST ANSWER

There's no need to use iplot anymore. Just set the pandas plotting backend to plotly with pd.options.plotting.backend = "plotly"and use df.plot().

Here's a setup using your example:

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

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

enter image description here

0
Valentin Laurent On

To supplement the accepted answer from @vestland: if you are plotting several figures, you may not want to use Plotly as the default backend for the whole session.

To use Plotly for a specific figure only:

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)