为什么python3不能运行代码“fig.show()”?

问题描述

json 文件

我有一个很大的 json 文件,我编写了一个程序来绘制它的数据:

import plotly.express as px
import pandas as pd
import json

filename = 'eq_data_1_day_m1.json'
with open(filename,encoding = "utf-8") as f:
    all_eq_data = json.load(f)
    
all_eq_dicts = all_eq_data['features']    
mags,titles,lons,lats = [],[],[]
for eq_dict in all_eq_dicts:
    mag = eq_dict['properties']['mag']
    title = eq_dict['properties']['title']
    lon = eq_dict['geometry']['coordinates'][0]
    lat = eq_dict['geometry']['coordinates'][1]
    mags.append(mag)
    titles.append(title)
    lons.append(lon)
    lats.append(lat)

#print(mags[:5])
#print(titles[:5])
#print(lons[:5])
#print(lats[:5])


fig = px.scatter(
    x = lons,y = lats,range_x=[-200,200],range_y=[-90,90],width=800,height=800,title = 'global_earthquakes'
)

fig.write_html('global_earthquakes.html')
fig.show()

然后vscode说它有一个UnicodeDecodeError:

UnicodeDecodeError
'utf-8' codec can't decode byte 0xd7 in position 0: invalid continuation byte
  File "C:\Users\asus\Desktop\Python_learning\lesson16\eq_explore_date.py",line 38,in <module>
    fig.show()

我该如何解决这个问题?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)