0

Hello I am trying to get a map visualization via pyplot but there is an error= PlotlyRequestError: Authentication credentials were not provided. I am trying to visualize Islam-adherence in the world this is my code data frame already there

from chart_studio import plotly as py
import plotly.tools as tls
data = [dict(type='choropleth',autocolorscale=False,locations=df['name'],z=df['islam'],locationmode="ISO-3",text="test",colorbar= dict(title="heyyo"))]
layout= dict(title="Islam adherence in the world ")
fig= dict(data=data, layout=layout)
py.iplot(fig,filename="ıslam-adherence")
fig= dict(data=data, layout=layout)
py.iplot(fig,filename="ıslam-adherence")

The thing that I don't understand is why I need to input some kind of username and password I am not trying to log in anywhere. Could you please help me thank you ...

luthierz
  • 51
  • 7
  • this is a duplicate of https://stackoverflow.com/questions/44024385/how-to-fix-plotlyrequesterror/44694854#44694854. what dev environment are you running in? – Rob Raymond Sep 03 '21 at 15:08

1 Answers1

1
  • How to fix PlotlyRequestError? you are trying to publish onto chart studio
  • either use
    1. go.Figure(fig)
    2. iplot(fig,filename="ıslam-adherence")
  • have sourced data from kaggle to be able to run your code

data sourcing

# https://www.kaggle.com/arthurtok/global-religion-1945-2010-plotly-pandas-visuals

import kaggle.cli
import sys, math
import pandas as pd
from pathlib import Path
from zipfile import ZipFile
import plotly.express as px

# download data set
# https://www.kaggle.com/umichigan/world-religions
sys.argv = [sys.argv[0]] + "datasets download umichigan/world-religions".split(" ")
kaggle.cli.main()

zfile = ZipFile("world-religions.zip")
print([f.filename for f in zfile.infolist()])

dfs = {f.filename: pd.read_csv(zfile.open(f)) for f in zfile.infolist()}

df = (
    dfs["national.csv"]
    .sort_values(["code", "year"])
    .groupby("code", as_index=False)
    .last()
    .assign(islam=lambda d: d["islam_percent"], name=lambda d: d["code"])
)

create and display plot

from chart_studio import plotly as py
import plotly.graph_objects as go
import plotly.tools as tls

data = [
    dict(
        type="choropleth",
        autocolorscale=False,
        locations=df["name"],
        z=df["islam"],
        locationmode="ISO-3",
        text=df["year"],
        colorbar=dict(title="heyyo"),
    )
]
layout = dict(title="Islam adherence in the world ")

from plotly.offline import init_notebook_mode, iplot
init_notebook_mode()

fig = dict(data=data, layout=layout)
iplot(fig,filename="ıslam-adherence")

enter image description here

Rob Raymond
  • 29,118
  • 3
  • 14
  • 30