Unable to see plot in jupyter notebook

Hello,

Iā€™m new to Python. Iā€™m trying to create a line diagram using plotly library. Below is the code that Iā€™m using.

layout = go.Layout(
title = ā€˜Transaction Valueā€™,
yaxis = dict(title = ā€˜Valueā€™),
xaxis = dict(title = ā€˜Monthā€™)
)
trace1 = go.Scatter(x = MSP[ā€˜Monthā€™], y = MSP[ā€˜2017ā€™], mode = ā€˜linesā€™, name = ā€˜Valueā€™, line = dict(shape = ā€˜splineā€™))
fig = go.Figure(data = [trace1], layout = layout)
py.offline.iplot(fig)

I can see the plot when I download it as PNG file but not able to see that in juypter notebook layout. Iā€™m using plotly version 4.1.0.

Please guide me on how to proceed.

@ayandeephalder With plotly 4.1.0 use
fig.show() to display your plot(figure) in the jupyter notebook.

I tried changing the code to fig.show() but still facing the same issue. Below is the complete code for your reference.

import plotly as py
import plotly.graph_objs as go
import ipywidgets as widgets
import numpy as np
import pandas as pd
py.offline.init_notebook_mode(connected = True)

MSP = pd.read_csv(ā€œD:/Data/Test.csvā€)
MSP.head()

layout = go.Layout(
title = ā€˜Transaction Valueā€™,
yaxis = dict(title = ā€˜Valueā€™),
xaxis = dict(title = ā€˜Monthā€™)
)
trace1 = go.Scatter(x = MSP[ā€˜Monthā€™], y = MSP[ā€˜2017ā€™], mode = ā€˜linesā€™, name = ā€˜Valueā€™, line = dict(shape = ā€˜splineā€™))
fig = go.Figure(data = [trace1], layout = layout)
fig.show()

Just add this importsā€¦

import plotly
from plotly import version
print (version)
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
init_notebook_mode(connected=True)

and then at last give this for plot.

fig = dict(data=data, layout=layout)
plotly.offline.plot(fig, filename = ā€˜plotā€™)

@ayandeephalder Or you donā€™t have plotly version 4.1.0 or your package installation is not complete, because
with this code like your, for me it displays the resulting figure:

import plotly.graph_objs as go

layout = go.Layout(width=500,
title = ā€˜Transaction Valueā€™,
yaxis = dict(title = ā€˜Valueā€™),
xaxis = dict(title = ā€˜Monthā€™))
trace1 = go.Scatter(x = [0,1,2,3], y=[3, 0, 1, 6], mode = ā€˜linesā€™,
name = ā€˜Valueā€™, line = dict(shape = ā€˜splineā€™))
fig = go.Figure(data = [trace1], layout = layout)

fig.show()

![spline_line|600x400](upload://uG7K9xxPubVuKvA8rzC27kE4gH4.jpeg)

I canā€™t see my plot! No instructions how to fix that.

hi @Worst_experience_eve
Iā€™m sorry you had a bad experience so far. I just recreated the code in your image and ran it on Pycharm and on Jupyter Notebook.
In both cases it worked for me.

import pandas as pd
us_cities = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/us-cities-top-1k.csv")

import plotly.express as px
fig = px.scatter_mapbox(us_cities, lat='lat', lon='lon', hover_name='City', hover_data=['State','Population'],
                        color_discrete_sequence=['fuchsia'], zoom=3, height=300)
fig.update_layout(mapbox_style='open-street-map')
fig.update_layout(margin={'r':0, 't':0, 'l':0, 'b':0})
fig.show()

Could it be that it doesnā€™t recognize that youā€™ve installed Pandas or Plotly Express? Can you share any other clues with us? Maybe we can solve it together.

adam

I apologize, I had a trouble running it in Sage-maker. Iā€™ve eventually figured out. Could you delete my comment please. Awesome library

I have tried for hours on end to make anything show with pyplot in jupyter notebook. I have used matplotlib for years but I see little to no logic with Plotly and canā€™t make it show graphic even just copy pasting from this thread or the official documentation.

I have gone through several threads showing extra imports to fix it, but no luck.

No error messages or any other info, absolutely nothing (visibly) happens when I run cells for Pyplot calls.

Same problem here. Does not show on Notebook while it worked before, and from nowhere, it stops appearing. No solution worked for me so far.