# json数据格式:列表或字典
import json
data = [{"name":"吉吉国王"}, {"name":"李元芳"}, {"name":"狄仁杰"}]
json_str = json.dumps(data, ensure_ascii=False) #正确显示中文,False表示不实用ascii码print(type(json_str))
print(json_str)
d = {"name":"吉吉国王", "addr":"花果山"}
# 字典转换成字符串(json数据)
json_str = json.dumps(d, ensure_ascii=False) #正确显示中文,False表示不实用ascii码
print(type(json_str))
print(json_str)
s = '[{"name":"吉吉国王"}, {"name":"李元芳"}, {"name":"狄仁杰"}]'
# 字符串转换成列表
l = json.loads(s)
print(type(l))
print(l)
d = '{"name":"吉吉国王", "addr":"花果山"}'
# 字符串转换成字典
json_str = json.loads(d)
print(type(json_str))
print(json_str)
# 画廊https://gallery.pyecharts.org/#/README
import pyecharts
# 一、基础折线图
from pyecharts.charts import Line
from pyecharts.options import TitleOpts, LegendOpts, ToolboxOpts, VisualMapOpts
#得到折线图对象
line = Line()
line.add_xaxis(["中国", "美国", "英国"])
line.add_yaxis("GDP", [30,20,25])
# 全局配置
line.set_global_opts(
title_opts=TitleOpts(title="GDP展示", pos_left="center", pos_bottom="1%"),
legend_opts=LegendOpts(is_show=True),
toolbox_opts=ToolboxOpts(is_show=True),
# 视觉映射器
visualmap_opts=VisualMapOpts(is_show=True)
)
# 生成图表
line.render()
Python学习——十、pyecharts数据可视化
最新推荐文章于 2024-07-26 10:52:40 发布