1

I am trying to plot using plotly offline. It works great, no errors, but I am unable to see any graph. It loads an empty graph! It is working for me in one instance of Jupyter notebook but not in another!

Code:

import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import re
import requests
import logging
import os
import json
import sys
import bokeh 
from ipywidgets import interact
from bokeh.io import push_notebook,show,output_notebook
from bokeh.plotting import figure
import cufflinks as cf
cf.set_config_file(world_readable=True,offline=False)
%matplotlib inline
import seaborn as sns
from plotly.offline import download_plotlyjs,init_notebook_mode,plot,iplot
init_notebook_mode(connected=True)
cf.go_offline()
from plotly.graph_objs import *

import plotly.plotly as py
import plotly.graph_objs as go
trace1 = go.Scatter(
    x=[0, 1, 2, 3, 4, 5],
    y=[1.5, 1, 1.3, 0.7, 0.8, 0.9]
)
trace2 = go.Scatter(
    x=[0, 1, 2, 3, 4, 5],
    y=[1, 0.5, 0.7, -1.2, 0.3, 0.4]
)

data = [trace1, trace2]
iplot(data, filename='bar-line')

Result is an empty graph!

1 Answer 1

1

Your code works in general but try reducing it to a minimal example. You are importing several libraries which are never used and Plotly submodules are imported multiple times, e.g. from plotly.graph_objs import * and import plotly.graph_objs as go. Perhaps one of the imported modules/functions is overwriting another one.

import plotly.graph_objs as go
from plotly.offline import init_notebook_mode, iplot
init_notebook_mode(connected=True)

trace1 = go.Scatter(
    x=[0, 1, 2, 3, 4, 5],
    y=[1.5, 1, 1.3, 0.7, 0.8, 0.9]
)
trace2 = go.Scatter(
    x=[0, 1, 2, 3, 4, 5],
    y=[1, 0.5, 0.7, -1.2, 0.3, 0.4]
)

data = [trace1, trace2]
iplot(data, filename='bar-line')

Or preferably to have a clean namespace:

import plotly

plotly.offline.init_notebook_mode(connected=True)

trace1 = plotly.graph_objs.Scatter(
    x=[0, 1, 2, 3, 4, 5],
    y=[1.5, 1, 1.3, 0.7, 0.8, 0.9]
)
trace2 = plotly.graph_objs.Scatter(
    x=[0, 1, 2, 3, 4, 5],
    y=[1, 0.5, 0.7, -1.2, 0.3, 0.4]
)

data = [trace1, trace2]
plotly.offline.iplot(data, filename='bar-line')

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Opened a new jupyter notebook to try your code tp get the same empty graph!
@Hariskrishna please add some information about your OS, environment, etc and try removing/installing or upgrading plotly via pip

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.