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.