After being fed up with Matplotlib, I'm looking into using Plotly. I have a simple plot made, however, whenever I try to create the plot the browser opens up and it is looking for "cdn cloudflare" or something like that. It hangs here for about a minute before finally showing some plots. Some plots don't even render such as the Scattergeo. Any idea on how to strip these dependencies? I'm working on a network that has no outside connection.
Note: This is test code. Change the if False to if True to run that portion of the code. I'm also using Plotly version 4.7.1
Here's some example code.
import plotly
import plotly.graph_objects as go
import plotly.io as pio
import numpy as np
import pandas as pd
pio.renderers.default = "browser"
size = 100
#Stacked Plot
if False:
fig = go.Figure()
#Data Creation
y1 = np.random.randint(0,50,size)
y2 = 50 - np.random.randint(0,25,size)
y3 = 100 - (y2+y1)
x = np.linspace(0,100,size)
#Plot Essentials
g = [go.Scatter(x=x,y=y1,mode='lines+markers',stackgroup='1',name='money'),
go.Scatter(x=x,y=y2,mode='lines+markers',stackgroup='1',name='credit'),
go.Scatter(x=x,y=y3,mode='lines+markers',stackgroup='1',name='IOU')]
for s in g:
fig.add_trace(s)
fig.update_layout(title=dict(text='Resource Plot'),
xaxis = dict(title = dict(text='Time (s)')),
yaxis = dict(title = dict(text='Resources Used (%)'),
ticksuffix = '%'))
pio.show(fig)
### Scatter Map Plot
if False:
fig = go.Figure()
#Data Creation
d = {'Lat':np.random.randint(90,120,size),
'Lon':np.random.randint(-180,180,size),
'colorcode':np.random.randint(-40,20,size)}
df = pd.DataFrame(d)
fig.add_trace(go.Scattergeo(mode = "markers+lines",lon = df['Lon'],lat = df['Lat'],marker = {'size': 10,'color':df['colorcode'],'colorscale':'jet','colorbar_thickness':20}))
fig.update_layout( geo = dict(
showland = True,
showcountries = True,
showocean = True,
countrywidth = 0.5,
landcolor = 'rgb(230, 145, 56)',
lakecolor = 'rgb(0, 255, 255)',
oceancolor = 'rgb(0, 255, 255)',
projection = dict(
type = 'orthographic',
),
lonaxis = dict(
showgrid = True,
gridcolor = 'rgb(102, 102, 102)',
gridwidth = 0.5
),
lataxis = dict(
showgrid = True,
gridcolor = 'rgb(102, 102, 102)',
gridwidth = 0.5
)
)
)
pio.show(fig)
Edit: I intend to render these plots in a QWebEngine that will be embedded inside our PyQt5 GUIs for analysis. It is okay if I can get them to render inside a web browser for now, since we have access to Firefox, granted no internet connection.
EDIT: Semi working answer. from plotly.offline import plot
plot(fig) works for some plots. But I still have issues with Scattergeo plots as in the html it still references www.w3.org. Any suggestions for map plots?
import plotly
you are getting the whole "enchilada"... including the parts that access plotly's servers. I don't think you need this line, if this helps I can provide a more formal answer. – jayveesea