""" 演示JSON数据和Python字典相互转换 """ # import json # # # 列表转换为json # data = [{"name": "张三", "age": 11}, {"name": '李四', "age": 21}] # json_str = json.dumps(data, ensure_ascii=False) # ensure_ascii=False,显示中文 # print(type(json_str)) # 类型为str # print(json_str) # # 字典转换为json # d = {"name": "张三", "age": 13} # json_str1 = json.dumps(d, ensure_ascii=False) # print(json_str1) # # # json转为python数据类型 # s = '[{"name": "张三", "age": 11}, {"name": "李四", "age": 21}]' # l = json.loads(s) # print(l) # print(type(l)) # d1 = '{"name": "张三", "age": 13}' # l1 = json.loads(d1) # print(d1) # print(type(d1)) # pyecharts入门 # 导包,导入line功能构建折线图对象 # from pyecharts.charts import Line # from pyecharts.options import TitleOpts, LegendOpts, ToolboxOpts # # # 得到折线图对象 # line = Line() # # 添加x轴数据 # line.add_xaxis(['中国', '英国', '美国']) # # 添加y轴数据 # line.add_yaxis("gdp", [30, 20, 10]) # # 生成图表 # # line.render() # # # 设置全局配置项 # line.set_global_opts( # title_opts=TitleOpts("gdp展示", pos_left="center", pos_bottom="1%"), # legend_opts=LegendOpts(is_show=True), # toolbox_opts=ToolboxOpts(is_show=True) # # ) # # line.render() # 演示地图可视化的基本使用 from pyecharts.charts import Map from pyecharts.options import VisualMapOpts # 准备地图对象 map = Map() # 准备数据 data = [ ("北京", 99), ("上海", 199), ("湖南", 299), ("台湾", 399), ("广东", 499) ] # 添加数据 map.add("测试地图", data, "china") # 设置全局变量 map.set_global_opts( visualmap_opts=VisualMapOpts( is_show=True, # 显示颜色 is_piecewise=True, # 手动校准范围 pieces=[ {"min": 1, "max": 9, "label": "1-9", "color": "#CCFFFF"}, {"min": 10, "max": 99, "label": "10-99", "color": "#FF6666"}, {"min": 100, "max": 999, "label": "100-999", "color": "#990033"} ] ) ) # 显示 map.render()