一,Json解析
字典转换为JSON:
import jsondata =[{"name":"袁震","age":20},{"name":"张三","age":21},{"name":"李四","age":22}]
str =json.dumps(data)
print(str)
将乱码转换为中文:
import jsondata =[{"name":"袁震","age":20},{"name":"张三","age":21},{"name":"李四","age":22}]
str =json.dumps(data,ensure_ascii=False)
print(str)
将Json字符串转换为列表:
import jsonjsonData ='[{"name":"袁震","age":20},{"name":"张三","age":21},{"name":"李四","age":22}]'
listData =json.loads(jsonData)
print("类型:",type(listData))
print(listData)
二,pyecharts模块
官方网站:https://pyecharts.org/#/zh-cn/
画廊网站:https://gallery.pyecharts.org/
pyecharts的安装:
基础折线图:
from pyecharts.charts import LinelistX =["语文","数学","英语","物理","化学","生物"]
listY =[100,120,130,80,90,70]
line =Line()
line.add_xaxis(listX)
line.add_yaxis("考试成绩",listY)
line.render()
设置全局配置:
from pyecharts.charts import Line
from pyecharts.options import TitleOpts,LegendOpts,ToolboxOpts,VisualMapOpts
listX =["语文","数学","英语","物理","化学","生物"]
listY =[100,120,130,80,90,70]
line =Line()
line.add_xaxis(listX)
line.add_yaxis("考试成绩",listY)
line.set_global_opts(title_opts=TitleOpts(title="袁震的成绩",pos_left="center",pos_bottom="1%"),#控制标题内容和位置legend_opts=LegendOpts(type_='plain',selected_mode=True,is_show=True,pos_left=None,pos_right=None,pos_top=None,pos_bottom=None,orient='horizontal',align='auto',padding=5,item_gap=10,item_width=25,item_height=14,inactive_color='#ccc',textstyle_opts=None,legend_icon=None),#图例toolbox_opts=ToolboxOpts(is_show=True),#工具箱visualmap_opts=VisualMapOpts(is_show=True)#视觉映射
)
line.render()