def Treemap(): treemap = TreeMap("树图示例", width=1200, height=600) import json with open("/root/nms_lqx/nms_dev/static/json/treemap-drill-down.json", "r", encoding="utf-8") as f: data = json.load(f) treemap.add("演示数据", data, is_label_show=True, label_pos='inside') return treemap
def education_show(): education_table = {} education_df = df['学历要求'] education_list = education_df.tolist() for x in list(set(education_list)): education_table[x] = education_list.count(x) keys = [] values = [] for k, v in education_table.items(): keys.append(k) values.append(v) data = [] for i in range(len(keys)): dict_01 = {} dict_01["value"] = values[i] dict_01["name"] = keys[i] data.append(dict_01) tree_map = TreeMap("学历要求", width=900) tree_map.add("学历要求", data, center=[40, 60], is_legend_show=False, is_label_show=True, label_pos='inside') tree_map.render(path="education.html")
def test_treemap_drilldown(): treemap = TreeMap("树图-下钻示例", width=1200, height=600) treemap.add("演示数据", data, is_label_show=True, label_pos='inside', treemap_left_depth=1) treemap.render()
def plot_tree(self, depth=3): from pyecharts import TreeMap data = self.describe_tree(self.tree_) tree_map = TreeMap(self.name, "", width=800, height=500) tree_map.use_theme("dark") tree_map.add(self.name, data, is_label_show=True, label_pos='inside', treemap_left_depth=depth) return tree_map
def showTreeMap(self, title, data): from pyecharts import TreeMap data = data treemap = TreeMap(title, width=1200, height=600) treemap.add("深圳", data, is_label_show=True, label_pos='inside', label_text_size=19) treemap.render()
def test_treemap_offcical_data(): treemap = TreeMap("树图-官方数据", width=1200, height=600) import os import json import codecs test_fixture = os.path.join("fixtures", "treemap.json") with codecs.open(test_fixture, "r", encoding="utf-8") as f: data = json.load(f) treemap.add("演示数据", data, is_label_show=True, label_pos="inside") treemap.render()
def education(self): print('{}:学历占比图 正在生成中。。。。。。。。。。。'.format(self.position)) edu = ['本科', '大专', '应届毕业生', '硕士', '博士'] data = [] # search_name = lagou.find({'search_name':position}) for i in edu: edu_count = self.lagou.count({'education': i, 'search_name': self.position}) # print(edu_count) data.append({'value': edu_count, 'name': i}) tree_map = TreeMap("{}学历要求".format(self.position), width=1200, height=600) tree_map.add('学历水平', data, is_label_show=True, label_pos='inside') tree_map.render('{}_学历.html'.format(self.position))
def showTreeMap(self, title, data): from pyecharts import TreeMap data = data treemap = TreeMap(title, width=1200, height=600) treemap.add("广州", data, is_label_show=True, label_pos='inside', label_text_size=19) treemap.render( r"c:\Users\Administrator\graduation design\spiderResult1\广州各区每平每月房租单价统计.html" )
def tree_map(): with open("../data/GDP_data_1.json", encoding="utf-8") as f: data_lzx = json.load(f) tree_map_lzx = TreeMap(title="2017年世界各个国家和地区的GDP-李兆旭", width=1000, height=600) tree_map_lzx.add(name="七大洲", data=data_lzx, is_label_show=True, label_pos="inside", treemap_left_depth=1) tree_map_lzx.render("TreeMapChart.html")
def CompanyAnalysis(self, items): loca_data = items['company'] list_data = set(loca_data) treemap_data = {} for item in list_data: treemap_data[item] = loca_data.count(item) print(treemap_data) data = self.getTreeData(treemap_data) # 转换为相应的TreeMap数据 print(data) treemap = TreeMap("重庆医疗相关公司分布图", width=1500, height=900, title_pos="center") treemap.add("公司数据", data, is_label_show=True, label_pos='inside', label_text_color='#000', is_legend_show=False) treemap.render()
def SalaryTreeAnalysis(self, items): salary_name = items['name'] salary_data = items['salaryMid'] salary_set = set(salary_name) treemap_data = {} for item in salary_set: treemap_data[item] = salary_data print(treemap_data) data = self.getTreeData(treemap_data) # 转换为相应的TreeMap数据 print(data) treemap = TreeMap("重庆医疗职位工资分布图", width=1500, height=900, title_pos="center") treemap.add("职位数据", data, is_label_show=True, label_pos='inside', label_text_color='#000', is_legend_show=False) treemap.render()
def plot(txtaddress, filepath): """ @Author: Haoyang Ding plot the interactive treemap html :param txtaddress: txt file address, string :return: None """ from pyecharts import TreeMap f = open(txtaddress, 'r') a = f.read() tree = eval(a) f.close() counter = 0 for i in range(len(tree)): counter += tree[i]["value"] for i in range(len(tree)): tree[i]["value"] = tree[i]["value"] / counter # change the ratio from region to global for i in tree: for j in i["children"]: j["value"] = j["value"] * i["value"] bcounter = round(counter / pow(10, 9)) def label(params): return params.name + "\n" + window.parseFloat( params.value * 100).toFixed(2) + r"%" + " " + "co2 emission" treemap = TreeMap(width=800, height=800, title_text_size=24, is_animation=True, renderer="canvas") treemap.add("Co2 emission in 10 years", tree, is_random=False, is_legend_show=True, line_opacity=0.5, is_label_show=True, label_pos="inside", legend_orient="vertical", label_formatter=label, is_more_utils=True, label_text_size=24) treemap.render(path=filepath)
def test_treemap_offcical_data(): treemap = TreeMap("树图-官方数据", width=1200, height=600) import os import json if PY2: import codecs test_fixture = os.path.join("..", "json", "treemap.json") with codecs.open(test_fixture, "rb") as f: data = json.load(f) else: with open(os.path.join("..", "json", "treemap.json"), "r", encoding="utf-8") as f: data = json.load(f) treemap.add("演示数据", data, is_label_show=True, label_pos='inside') treemap.render()
def test_treemap_offcical_data(): treemap = TreeMap("树图-官方数据", width=1200, height=600) import os import json if PY2: import codecs with codecs.open(os.path.join("..", "json", "treemap.json"), "rb") as f: data = json.load(f) else: with open(os.path.join("..", "json", "treemap.json"), "r", encoding="utf-8") as f: data = json.load(f) treemap.add("演示数据", data, is_label_show=True, label_pos='inside') treemap.render()
def create_type_likes(df): """ 类型点赞数 """ dom = [] print(df) likes_type_message = df.groupby(['type']) likes_type_com = likes_type_message['likes'].agg(['sum']) # 统计 likes_type_com.reset_index(inplace=True) for name, num in zip(likes_type_com['type'], likes_type_com['sum']): data = {} data['name'] = name data['value'] = num dom.append(data) # 生成矩形树图 treemap = TreeMap('各类型抖音大V点赞数汇总图', title_pos='center', title_top='5', width=800, height=400) treemap.add('各类型抖音大V点赞数汇总图', dom, is_label_show=True, label_pos='inside', is_legend_show=False) treemap.render('各类型抖音大V点赞数汇总图.html')
def test_treemap(): data = [{ "value": 40, "name": "我是A", }, { "value": 180, "name": "我是B", "children": [{ "value": 76, "name": "我是B.children", "children": [{ "value": 12, "name": "我是B.children.a", }, { "value": 28, "name": "我是B.children.b", }, { "value": 20, "name": "我是B.children.c", }, { "value": 16, "name": "我是B.children.d", }] }] }] # 默认示例 treemap = TreeMap("树图示例", width=1200, height=600) treemap.add("演示数据", data, is_label_show=True, label_pos='inside') treemap.render() # 下钻示例 treemap = TreeMap("树图示例", width=1200, height=600) treemap.add("演示数据", data, is_label_show=True, label_pos='inside', treemap_left_depth=1) treemap.render()
def plot_education_tree(): education = read_detail_data_from_csv('Python爬虫.csv', col=1) education_table = {} for x in education: education_table[x] = education.count(x) key = [] values = [] for k, v in education_table.items(): key.append(k) values.append(v) data = [] for i in range(len(key)): dict_01 = {'value': values[i], 'name': key[i]} data.append(dict_01) tree_map = TreeMap('矩形树图', width=1200, height=600) tree_map.add('学历要求', data, is_label_show=True, label_pos='inside') tree_map.render('tree.html')
num += 1 else: continue dom2.append(num) def message(): for k in range(len(dom2)): data = {} data['name'] = dom1[k] + ' ' + str(dom2[k]) data['value'] = dom2[k] yield data data1 = message() dom3 = [] for item in data1: dom3.append(item) treemap = TreeMap("2018年电影类型分布图", title_pos='center', title_top='5', width=800, height=400) treemap.add('2018年电影类型分布', dom3, is_label_show=True, label_pos='inside', is_legend_show=False) treemap.render('2018年电影类型分布图.html')
num += 1 else: continue dom2.append(num) def message(): for k in range(len(dom2)): data = {} data['name'] = dom1[k] + ' ' + str(dom2[k]) data['value'] = dom2[k] yield data data1 = message() dom3 = [] for item in data1: dom3.append(item) treemap = TreeMap("拉勾网数据分析岗—技能图", title_pos='center', title_top='5', width=1200, height=600) treemap.use_theme("wonderland") treemap.add('数据分析技能', dom3, is_label_show=True, label_pos='inside', is_legend_show=False) treemap.render('拉勾网数据分析岗—技能图.html')
def test_treemap_default(): treemap = TreeMap("树图-默认示例", width=1200, height=600) treemap.add("演示数据", data, is_label_show=True, label_pos="inside") treemap.render()
def test_treemap_default(): treemap = TreeMap("树图-默认示例", width=1200, height=600) treemap.add("演示数据", data, is_label_show=True, label_pos='inside') treemap.render()
overlap.add(bar, yaxis_index=1, is_add_yaxis=True) overlap.render('TOP20女演员评分_出生年份.html') ## 星座分布图 from pyecharts import TreeMap, WordCloud star_stat = actor_data.groupby('xingzuo').agg({ 'name': 'count' }).reset_index().sort_values('name', ascending=False)[0:12].reset_index() data = [{ 'value': star_stat['name'][i], 'name': star_stat['xingzuo'][i] + ' ' + str(star_stat['name'][i]) } for i in range(star_stat.shape[0])] treemap = TreeMap("星座分布图", width=1200, height=600) treemap.add("星座分布", data, is_label_show=True, label_pos='inside') treemap.render('星座分布.html') ## 城市分布图 city_stat = actor_data.groupby('hometown').agg({'name': 'count'}).reset_index() city_stat = city_stat[~city_stat['hometown'].isin(['香港', '台湾'])].sort_values( 'name', ascending=False)[0:30].reset_index() data = [{ 'value': city_stat['name'][i], 'name': city_stat['hometown'][i] + ' ' + str(city_stat['name'][i]) } for i in range(city_stat.shape[0])] treemap = TreeMap("TOP30城市分布图", width=1500, height=900) treemap.add("TOP30城市分布", data, is_label_show=True, label_pos='inside') treemap.render('城市分布.html')
'itemStyle': { 'normal': { 'borderColor': '#555', 'borderWidth': 5, 'gapWidth': 1 }, 'emphasis': { 'borderColor': '#ddd' } } }, { 'colorSaturation': [0.35, 0.5], 'itemStyle': { 'normal': { 'borderWidth': 5, 'gapWidth': 1, 'borderColorSaturation': 0.6 } } }] treemap = TreeMap("树图-下钻示例", width=1200, height=600) treemap.add("演示数据", data, is_label_show=True, label_pos='inside', treemap_left_depth=2) for series in treemap._option['series']: series['upperLabel'] = dict(normal=dict( show=True, height=30)) series['levels'] = getLevelOption() treemap.render()
res = j.split(' ') for re in res: if re == k: num += 1 dom3.append(num) def message(): # 生成字典形式 for p in range(len(dom2)): data = {} data['name'] = dom2[p] + ' ' + str(dom3[p]) data['value'] = dom3[p] yield data # 生成类型图 data = message() for item in data: dom4.append(item) treemap = TreeMap("豆瓣电影TOP250-电影类型图", title_pos='center', title_top='5', width=800, height=400) treemap.add('电影类型', dom4, is_label_show=True, label_pos='inside', is_legend_show=False) treemap.render('豆瓣电影TOP250电影类型图.html')