I am running the following code to plot points against a city backdrop using Mapbox within Plotly in a Jupyter Notebook, but the plot does not show up, I just get a blue background.
I suspect that I am not using the token correctly?
import plotly.express as px
MBToken = 'pk.[mypublickey]'
px.set_mapbox_access_token(MBToken)
fig = px.scatter_mapbox(dfMaster.dropna()
, lat="latitude"
, lon="longitude"
, color="nta"
, size="count_of_testers"
#, color_continuous_scale=px.colors.cyclical.IceFire
#, size_max=15
#, zoom=10
)
fig.show()
#fig = px.scatter(x='latitude',y='longitude',data_frame=df)
#fig.show()
Running that gives me:
It does not appear to be a Plotly issue, the commented out code creates a scatter plot (although that has the same blue background, but the points show)
Some other posts have pointed to Jupyter offline mode being the possible culprit, but adding this did not resolve
import plotly.offline as pyo
pyo.init_notebook_mode()
Additionally, tried starting up the Jupyter notebook with a higher data rate limit as suggested, but no luck there either
This ended up being a silent data integrity error, as the size field was a string and needed to be converted into numeric
Related
I tried the following example 3D Mesh example with AlphaNull to test alphahull but my jupyter notebook display just something blank.
When I set alphahull=5, the display is blank:
But when i set alphahull = 0, it works:
and when i set alphahull = -1, it works :
Why is this happening and how can I fix it?
Thank you in advance for your help.
Unfortunately I think rendering for alphahull values larger than 0 may be broken as of the latest plotly update. I noticed that in the documentation page, their code example with alphahull=5 also doesn't render. I tried with other positive values and none of these render either (the same alpha shape algorithm is used for any alphanull > 0)
However, I tried downgrading to plotly==4.14.0 and the same example with alphahull=5 does render.
import plotly.graph_objects as go
import numpy as np
pts = np.loadtxt(np.DataSource().open('https://raw.githubusercontent.com/plotly/datasets/master/mesh_dataset.txt'))
x, y, z = pts.T
fig = go.Figure(data=[go.Mesh3d(x=x, y=y, z=z,
alphahull=5,
opacity=0.4,
color='cyan')])
fig.show()
So in your jupyter notebook, you can run the line !pip install plotly==4.14.0 in a separate cell and see if that allows you to render positive alphahull values.
Trying to display a 3D plot generated with UMAP and plotly.express (px). here's my code:
data_norm is a numpy array. This code generates a blank space in jupyter notebook. The 2d version of this displays a plot though. This exact code worked in another jupyter notebook (same computer) but with 8 features instead of 8000 that I have now.
umap_3d = umap.UMAP(n_components=3, init='random', random_state=0)
proj_3d = umap_3d.fit_transform(data_norm)
fig_3d = px.scatter_3d(
proj_3d, x=0, y=1, z=2,
color=df["cluster #"].astype(str), labels={'color': 'cluster #'}
)
fig_3d.update_traces(marker_size=20)
fig_3d.show()
FIGURED IT OUT, add this line:
plotly.offline.init_notebook_mode(connected=True)
Below shown the syntax used to get a map visualized and plotted from Plotly Express - choropleth from a "csv" DataFrame.
import pandas as pd
import numpy as np
import plotly.express as px
df = "//location.csv"
fig = px.choropleth(data_frame = df,
locations= df["location"],
locationmode='country names',
color=df["location"],
hover_name=df["location"],
title = "Location Data",
color_continuous_scale = px.colors.sequential.Oranges)
fig["layout"].pop("updatemenus")
fig.show()
However, when I use the above syntax on the Visual Studio Code Jupyter Notebook, the map does not get visualized and plotted. Which is shown as below,
But when I run the same code on the Anaconda Jupyter Notebook, I do get the map visualized and plotted as shown below,
Why isn't the map not getting visualized and plotted on VS code, and is there any way to resolve this issue on VS code?
I was interested in this question because I usually work with jypyterLab. I ran it based on this answer, and when I ran it in vscode, it displayed correctly in my default browser. The code I ran was based on the code in the official reference.
import plotly.express as px
from plotly.offline import plot
df = px.data.gapminder().query("year==2007")
fig = px.choropleth(df, locations="iso_alpha",
color="lifeExp", # lifeExp is a column of gapminder
hover_name="country", # column to add to hover information
color_continuous_scale=px.colors.sequential.Plasma)
# fig.show()
plot(fig)
I am trying to plot a USA map using plotly package. Code is getting executed but nothing is getting displayed on the screen.
import plotly.graph_objs as go
import pandas as pd
data = dict(type = 'choropleth',locations = ['AZ','CA','NY'],locationmode='USA-states',colorscale='Portland',text=['text1','text2','text3']
,z=[1,0,2.0,3.0],colorbar={'title' : 'USA States Data'})
layout = dict(geo={'scope' : 'usa'})
fig = go.Figure(data=[data],layout=layout)
fig.show()
Why nothing is getting displayed and no error is also raised?
Ran your code, it's working fine for me.
(Also, try and make your title more descriptive of the problem so that if someone faces a similar problem, they can easily find your question.)
I'm trying to produce a dashboard with plotly, wherein the graphs are sourced off a loaded dataframe. My problem currently is that upon creating a bar chart, the output is blank, even when I use a line chart, it works fine.
Here is a preview of my dataset:
It's a grouped-by object, I essentially have a larger dataset that I wanted topline figures for showing topline time series trends.
preview of my dataset
data set types
import plotly.offline as offline
import plotly.graph_objs as go
data = [go.Bar(
x=[Safe.Period],
y=[Safe.Units]
)]
pl.offline.iplot(data, filename='basic-bar')
To which I get this blank output:
blank output
Now I've got it to work like this:
trace = go.Scatter(x= Topline.Period,
y= Topline.Units,
mode = "lines")
data = [trace]
pl.offline.iplot({"data":data})
Line chart
So in a line chart, or at least a scatter connected by lines, the code works. but not when its done as a bar chart.
Can anybody shed some light on this/ recommend any fixes/checks? I'm still getting accustomed to plotly and hope to one day move my excel dashboarding into python/plotly.