예제 #1
0
def test_treemap_base():
    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"},
                    ],
                }
            ],
        },
    ]

    c = TreeMap().add("演示数据", data)
    assert c.theme == "white"
    assert c.renderer == "canvas"
    c.render("render.html")
예제 #2
0
def test_treemap_base(fake_writer):
    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"},
                    ],
                }
            ],
        },
    ]

    c = TreeMap().add("演示数据", data)
    c.render()
    _, content = fake_writer.call_args[0]
    eq_(c.theme, "white")
    eq_(c.renderer, "canvas")
def draw_tree_picture(data, to_file, svg_name, colors=None):
    c = TreeMap(init_opts=opts.InitOpts(width="800px", height="600px", bg_color='white')) \
        .add("", data) \
        .set_global_opts(legend_opts=opts.LegendOpts(is_show=False), ) \
        .set_series_opts(label_opts=opts.LabelOpts(formatter="{b}: {c}", position='top'))
    c.render(to_file)
    to_svg(to_file, svg_name)
예제 #4
0
def test_treemap_options(fake_writer):
    c = TreeMap().add("演示数据", example_data, width="90%", height="100%", roam=False)
    c.render()
    _, content = fake_writer.call_args[0]
    assert_in("width", content)
    assert_in("height", content)
    assert_in("roam", content)
예제 #5
0
def create_type_likes(df):
    # 分组求和
    likes_type_message = df.groupby(['category'])
    likes_type_com = likes_type_message['likes'].agg(['sum'])
    likes_type_com.reset_index(inplace=True)
    # 处理数据
    dom = []
    for name, num in zip(likes_type_com['category'], likes_type_com['sum']):
        data = {}
        data['name'] = name
        data['value'] = num
        dom.append(data)
    print(dom)

    # 初始化配置
    treemap = TreeMap(init_opts=opts.InitOpts(width="800px", height="400px"))
    # 添加数据
    treemap.add('', dom)
    # 设置全局配置项,标题、工具箱(下载图片)
    treemap.set_global_opts(title_opts=opts.TitleOpts(title="各类型抖音大V点赞数汇总图",
                                                      pos_left="center",
                                                      pos_top="5"),
                            toolbox_opts=opts.ToolboxOpts(
                                is_show=True, feature={"saveAsImage": {}}),
                            legend_opts=opts.LegendOpts(is_show=False))

    treemap.render("各类型抖音大V点赞数汇总图.html")
예제 #6
0
def test_treemap_levels_options(fake_writer):
    c = TreeMap().add(
        "演示数据",
        example_data,
        width="90%",
        height="100%",
        roam=False,
        levels=opts.TreeMapLevelsOpts(),
    )
    c.render()
    _, content = fake_writer.call_args[0]
    assert_in("levels", content)
예제 #7
0
def test_treemap_options(fake_writer):
    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"
                    },
                ],
            }],
        },
    ]

    c = TreeMap().add("演示数据", data, width="90%", height="100%", roam=False)
    c.render()
    _, content = fake_writer.call_args[0]
    assert_in("width", content)
    assert_in("height", content)
    assert_in("roam", content)
예제 #8
0
def test_treemap_base():
    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"
                    },
                ],
            }],
        },
    ]

    c = TreeMap().add("演示数据", data)
    eq_(c.theme, "white")
    eq_(c.renderer, "canvas")
    c.render()
예제 #9
0
    def make_star_treemap(self):
        """
        根据演员参演电影数生成矩形树图
        :return:
        """
        # print(get_current_time() + '|-------> 正在生成 演员参演电影数 图表...')
        # 导入数据并初始化
        csv_path = os.path.abspath(os.path.join(os.path.dirname("__file__"), os.path.pardir, "moviespider", "movie_info_top500.csv"))
        rows = pd.read_csv(csv_path, encoding='utf-8', dtype=str)
        # rows = pd.read_csv('../comments/movie_info_top500.csv', encoding='utf-8', dtype=str)
        to_drop = ['名称', '导演', '年份', '国别', '类型', '语言', '评分', '评分人数', '五星占比', '四星占比', '三星占比', '二星占比', '一星占比', '短评数',
                   '简介']
        res = rows.drop(to_drop, axis=1)
        # 数据分割
        all_star_list = []
        for i in res.itertuples():
            #     print(i[1] + '\n')
            for j in i[1].split(','):
                all_star_list.append(j)
        # 数据统计
        df = pd.DataFrame(all_star_list, columns=['演员'])
        res = df.groupby('演员')['演员'].count().sort_values(ascending=False)
        all_star_list = []
        for i in res.items():
            if i[1] > 4:
                all_star_list.append({"value": i[1], "name": i[0]})
        # 生成图标
        c = TreeMap()
        c.add("参演电影数", all_star_list)
        c.set_global_opts(title_opts=opts.TitleOpts(title="电影TOP500榜单中 - 演员参演电影数", subtitle="至少参演5部影评以上"))

        htmlPath = os.path.abspath(os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(__file__))), "analyse_data", "演员参演电影数.html"))
        pngPath = os.path.abspath(os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(__file__))), "analyse_data", "演员参演电影数.png"))
        # 生成html
        c.render(htmlPath)
        # 生成png
        # make_snapshot(snapshot, c.render(), pngPath)
        # print(get_current_time() + '|-------> 已生成 演员参演电影数 图表...')
        return c
예제 #10
0
def create_type_fans(df):
    dom = []
    fans_type_message = df.groupby(['category'])
    fans_type_com = fans_type_message['fans'].agg(['sum'])
    fans_type_com.reset_index(inplace=True)
    for name, num in zip(fans_type_com['category'], fans_type_com['sum']):
        data = {}
        data['name'] = name
        data['value'] = num
        dom.append(data)
    print(dom)

    treemap = TreeMap(init_opts=opts.InitOpts(width="800px", height="400px"))
    treemap.add('', dom)
    treemap.set_global_opts(title_opts=opts.TitleOpts(title="各类型抖音大V粉丝数汇总图",
                                                      pos_left="center",
                                                      pos_top="5"),
                            toolbox_opts=opts.ToolboxOpts(
                                is_show=True, feature={"saveAsImage": {}}),
                            legend_opts=opts.LegendOpts(is_show=False))
    treemap.set_series_opts(treemapbreadcrumb_opts=opts.TreeMapBreadcrumbOpts(
        is_show=False))
    treemap.render("各类型抖音大V粉丝数汇总图.html")
예제 #11
0
def show_genres():
    data=select_data()
    # 矩形树图初始化
    treemap = TreeMap(init_opts=opts.InitOpts(page_title="豆瓣电影-电影类型分布"))
    # 添加数据
    treemap.add(
        series_name='电影类型',
        data=data,
        # 标签居中
        label_opts=opts.LabelOpts(font_size=15, position="inside"),
    )
    # 全局配置
    treemap.set_global_opts(
        # 标题
        title_opts=opts.TitleOpts(
            title="豆瓣电影-电影类型分布", pos_left='center'
        ),
        # 标签隐藏
        legend_opts=opts.LegendOpts(is_show=False)
    )
    # 生成HTML
    html="pages/iframes/genres.html"
    treemap.render("./templates/"+html)
    return html
예제 #12
0
 def plot_tree(self, depth=3):
     data = self.describe_tree(self.tree)
     tree_map = TreeMap()
     tree_map.add(self.name, data, leaf_depth=depth, width=800, height=600)
     tree_map.render()
     return tree_map
예제 #13
0
def test_treemap_base(fake_writer):
    c = TreeMap().add("演示数据", example_data)
    c.render()
    _, content = fake_writer.call_args[0]
    assert_equal(c.theme, "white")
    assert_equal(c.renderer, "canvas")
예제 #14
0
import json
from pyecharts.charts import TreeMap
import pyecharts.options as opts

with open('GDP_data_1.json', 'r', encoding='utf-8') as f:
    j = json.load(f)
    data = [j]

map = TreeMap(init_opts=opts.InitOpts(width='1200px', height='800px'))
map.add(
    '',
    data,
    label_opts=opts.LabelOpts(position='inside'),
)

map.render('map.html')
예제 #15
0
import json
from pyecharts.charts import TreeMap
import pyecharts.options as opts

with open('GDP_data_1.json', 'r', encoding='utf-8') as f:
    j = json.load(f)
    data = [j]

map = TreeMap(
    init_opts=opts.InitOpts(width='1200px', height='800px')
)
map.add('', data, label_opts=opts.LabelOpts(position='inside'), leaf_depth=1)

map.render('map(1).html')