微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决为什么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 举报,一经查实,本站将立刻删除。