(6)所有角色数据分析-6

http://t.csdn.cn/KrurEhttp://t.csdn.cn/KrurE

(5)中的页面,倾向于向用户展示所有数据,但却没有对数据进行比较、分析,用户不能直观的感受到各种数据之间的关系与变化幅度,所以,下面将向用户提供一个可以直观感受到数据变化的页面:
话不多说,上货!

python 复制代码
"""绘图"""
from pyecharts.charts import Timeline
from pyecharts.options import ToolboxOpts

from find_type import FindType
import pandas as pd
from pyecharts.charts import Bar, Page
from pyecharts import options as opts
from pyecharts.charts import Scatter


# 全部角色
def x():
    tl = Timeline()
    for i in ["火", "水", "冰", "风", "雷", "岩"]:
        role_things = pd.read_excel("C:/Users/YHT/Desktop/项目/原神各属性角色信息.xlsx", header=0, index_col=0)
        role_things = role_things.fillna(axis=0, method="ffill")
        things_list = role_things.groupby("属性").groups
        print(role_things.loc[things_list[i]]["角色"])
        bar = (
            Bar()
            .add_xaxis(list(role_things.loc[things_list[i]]["角色"]))
            .add_yaxis("生命值", list(role_things.loc[things_list[i]]["生命值"]))
            .add_yaxis("防御力", list(role_things.loc[things_list[i]]["防御力"]))
            .add_yaxis("攻击力", list(role_things.loc[things_list[i]]["攻击力"]))
            .set_global_opts(toolbox_opts=ToolboxOpts(is_show=True), title_opts=opts.TitleOpts())
        )
        tl.add(bar, f"{i}属性")
    return tl


# 火
def y():
    return_things = FindType("火").find_type()
    df = return_things.drop(["属性", "突破加成"], axis=1)
    list_source = [["produce", "max", "min"]]
    print(df)
    list_source = list_source + [["生命值"] + list(df[df["生命值"] == df["生命值"].max()]["生命值"]) + list(
        df[df["生命值"] == df["生命值"].max()]["生命值"])] + [
                      ["防御力"] + list(df[df["防御力"] == df["防御力"].max()]["防御力"]) + list(
                          df[df["防御力"] == df["防御力"].max()]["防御力"])] + [
                      ["攻击力"] + list(df[df["攻击力"] == df["攻击力"].max()]["攻击力"]) + list(
                          df[df["攻击力"] == df["攻击力"].max()]["攻击力"])]
    c = (
        Bar()
        .add_dataset(
            source=list_source
        )
        .add_yaxis(series_name="max", y_axis=[])
        .add_yaxis(series_name="min", y_axis=[])
        .set_global_opts(
            toolbox_opts=ToolboxOpts(is_show=True),
            title_opts=opts.TitleOpts(title="火属性"),
            xaxis_opts=opts.AxisOpts(type_="category"),
        )
    )
    return c


# 水
def z():
    return_things = FindType("水").find_type()
    df = return_things.drop(["属性", "突破加成"], axis=1)
    list_source = [["produce", "max", "min"]]
    print(df)
    list_source = list_source + [["生命值"] + list(df[df["生命值"] == df["生命值"].max()]["生命值"]) + list(
        df[df["生命值"] == df["生命值"].max()]["生命值"])] + [
                      ["防御力"] + list(df[df["防御力"] == df["防御力"].max()]["防御力"]) + list(
                          df[df["防御力"] == df["防御力"].max()]["防御力"])] + [
                      ["攻击力"] + list(df[df["攻击力"] == df["攻击力"].max()]["攻击力"]) + list(
                          df[df["攻击力"] == df["攻击力"].max()]["攻击力"])]
    c = (
        Bar()
        .add_dataset(
            source=list_source
        )
        .add_yaxis(series_name="max", y_axis=[])
        .add_yaxis(series_name="min", y_axis=[])
        .set_global_opts(
            toolbox_opts=ToolboxOpts(is_show=True),
            title_opts=opts.TitleOpts(title="水属性"),
            xaxis_opts=opts.AxisOpts(type_="category"),
        )
    )
    return c


# 冰
def a():
    return_things = FindType("冰").find_type()
    df = return_things.drop(["属性", "突破加成"], axis=1)
    list_source = [["produce", "max", "min"]]
    print(df)
    list_source = list_source + [["生命值"] + list(df[df["生命值"] == df["生命值"].max()]["生命值"]) + list(
        df[df["生命值"] == df["生命值"].max()]["生命值"])] + [
                      ["防御力"] + list(df[df["防御力"] == df["防御力"].max()]["防御力"]) + list(
                          df[df["防御力"] == df["防御力"].max()]["防御力"])] + [
                      ["攻击力"] + list(df[df["攻击力"] == df["攻击力"].max()]["攻击力"]) + list(
                          df[df["攻击力"] == df["攻击力"].max()]["攻击力"])]
    c = (
        Bar()
        .add_dataset(
            source=list_source
        )
        .add_yaxis(series_name="max", y_axis=[])
        .add_yaxis(series_name="min", y_axis=[])
        .set_global_opts(
            toolbox_opts=ToolboxOpts(is_show=True),
            title_opts=opts.TitleOpts(title="冰属性"),
            xaxis_opts=opts.AxisOpts(type_="category"),
        )
    )
    return c


# 风
def b():
    return_things = FindType("风").find_type()
    df = return_things.drop(["属性", "突破加成"], axis=1)
    list_source = [["produce", "max", "min"]]
    print(df)
    list_source = list_source + [["生命值"] + list(df[df["生命值"] == df["生命值"].max()]["生命值"]) + list(
        df[df["生命值"] == df["生命值"].max()]["生命值"])] + [
                      ["防御力"] + list(df[df["防御力"] == df["防御力"].max()]["防御力"]) + list(
                          df[df["防御力"] == df["防御力"].max()]["防御力"])] + [
                      ["攻击力"] + list(df[df["攻击力"] == df["攻击力"].max()]["攻击力"]) + list(
                          df[df["攻击力"] == df["攻击力"].max()]["攻击力"])]
    c = (
        Bar()
        .add_dataset(
            source=list_source
        )
        .add_yaxis(series_name="max", y_axis=[])
        .add_yaxis(series_name="min", y_axis=[])
        .set_global_opts(
            toolbox_opts=ToolboxOpts(is_show=True),
            title_opts=opts.TitleOpts(title="风属性"),
            xaxis_opts=opts.AxisOpts(type_="category"),
        )
    )
    return c


# 雷
def c():
    return_things = FindType("雷").find_type()
    df = return_things.drop(["属性", "突破加成"], axis=1)
    list_source = [["produce", "max", "min"]]
    print(df)
    list_source = list_source + [["生命值"] + list(df[df["生命值"] == df["生命值"].max()]["生命值"]) + list(
        df[df["生命值"] == df["生命值"].max()]["生命值"])] + [
                      ["防御力"] + list(df[df["防御力"] == df["防御力"].max()]["防御力"]) + list(
                          df[df["防御力"] == df["防御力"].max()]["防御力"])] + [
                      ["攻击力"] + list(df[df["攻击力"] == df["攻击力"].max()]["攻击力"]) + list(
                          df[df["攻击力"] == df["攻击力"].max()]["攻击力"])]
    c = (
        Bar()
        .add_dataset(
            source=list_source
        )
        .add_yaxis(series_name="max", y_axis=[])
        .add_yaxis(series_name="min", y_axis=[])
        .set_global_opts(
            toolbox_opts=ToolboxOpts(is_show=True),
            title_opts=opts.TitleOpts(title="雷属性"),
            xaxis_opts=opts.AxisOpts(type_="category"),
        )
    )
    return c


# 岩
def d():
    return_things = FindType("岩").find_type()
    df = return_things.drop(["属性", "突破加成"], axis=1)
    list_source = [["produce", "max", "min"]]
    print(df)
    list_source = list_source + [["生命值"] + list(df[df["生命值"] == df["生命值"].max()]["生命值"]) + list(
        df[df["生命值"] == df["生命值"].max()]["生命值"])] + [
                      ["防御力"] + list(df[df["防御力"] == df["防御力"].max()]["防御力"]) + list(
                          df[df["防御力"] == df["防御力"].max()]["防御力"])] + [
                      ["攻击力"] + list(df[df["攻击力"] == df["攻击力"].max()]["攻击力"]) + list(
                          df[df["攻击力"] == df["攻击力"].max()]["攻击力"])]
    c = (
        Bar()
        .add_dataset(
            source=list_source
        )
        .add_yaxis(series_name="max", y_axis=[])
        .add_yaxis(series_name="min", y_axis=[])
        .set_global_opts(
            toolbox_opts=ToolboxOpts(is_show=True),
            title_opts=opts.TitleOpts(title="岩属性"),
            xaxis_opts=opts.AxisOpts(type_="category"),
        )
    )
    return c


def e():
    role_things = pd.read_excel("C:/Users/YHT/Desktop/项目/原神各属性角色信息.xlsx", header=0, index_col=0)
    role_things = role_things.fillna(axis=0, method="ffill")
    print(role_things)
    return_things = FindType("岩").find_type()
    df = return_things.drop(["属性", "突破加成"], axis=1)
    Name = df["角色"]
    Hp = df["生命值"]
    Def = df["防御力"]
    Atk = df["攻击力"]
    c = (
        Scatter()
        .add_xaxis(list(Name))
        .add_yaxis("生命值", list(Hp))
        .add_yaxis("防御力", list(Def))
        .add_yaxis("攻击力", list(Atk))
        .set_global_opts(
            toolbox_opts=ToolboxOpts(is_show=True),
            title_opts=opts.TitleOpts(title="岩属性"),
            visualmap_opts=opts.VisualMapOpts(type_="size", max_=150, min_=20),
            xaxis_opts=opts.AxisOpts(axislabel_opts={"rotate": 45})
        )
    )
    return c


def f():
    role_things = pd.read_excel("C:/Users/YHT/Desktop/项目/原神各属性角色信息.xlsx", header=0, index_col=0)
    role_things = role_things.fillna(axis=0, method="ffill")
    print(role_things)
    return_things = FindType("火").find_type()
    df = return_things.drop(["属性", "突破加成"], axis=1)
    Name = df["角色"]
    Hp = df["生命值"]
    Def = df["防御力"]
    Atk = df["攻击力"]
    c = (
        Scatter()
        .add_xaxis(list(Name))
        .add_yaxis("生命值", list(Hp))
        .add_yaxis("防御力", list(Def))
        .add_yaxis("攻击力", list(Atk))
        .set_global_opts(
            toolbox_opts=ToolboxOpts(is_show=True),
            title_opts=opts.TitleOpts(title="火属性"),
            visualmap_opts=opts.VisualMapOpts(type_="size", max_=150, min_=20),
            xaxis_opts=opts.AxisOpts(axislabel_opts={"rotate": 45})
        )
    )
    return c


def g():
    role_things = pd.read_excel("C:/Users/YHT/Desktop/项目/原神各属性角色信息.xlsx", header=0, index_col=0)
    role_things = role_things.fillna(axis=0, method="ffill")
    print(role_things)
    return_things = FindType("水").find_type()
    df = return_things.drop(["属性", "突破加成"], axis=1)
    Name = df["角色"]
    Hp = df["生命值"]
    Def = df["防御力"]
    Atk = df["攻击力"]
    c = (
        Scatter()
        .add_xaxis(list(Name))
        .add_yaxis("生命值", list(Hp))
        .add_yaxis("防御力", list(Def))
        .add_yaxis("攻击力", list(Atk))
        .set_global_opts(
            toolbox_opts=ToolboxOpts(is_show=True),
            title_opts=opts.TitleOpts(title="水属性"),
            visualmap_opts=opts.VisualMapOpts(type_="size", max_=150, min_=20),
            xaxis_opts=opts.AxisOpts(axislabel_opts={"rotate": 45})
        )
    )
    return c


def h():
    role_things = pd.read_excel("C:/Users/YHT/Desktop/项目/原神各属性角色信息.xlsx", header=0, index_col=0)
    role_things = role_things.fillna(axis=0, method="ffill")
    print(role_things)
    return_things = FindType("冰").find_type()
    df = return_things.drop(["属性", "突破加成"], axis=1)
    Name = df["角色"]
    Hp = df["生命值"]
    Def = df["防御力"]
    Atk = df["攻击力"]
    c = (
        Scatter()
        .add_xaxis(list(Name))
        .add_yaxis("生命值", list(Hp))
        .add_yaxis("防御力", list(Def))
        .add_yaxis("攻击力", list(Atk))
        .set_global_opts(
            toolbox_opts=ToolboxOpts(is_show=True),
            title_opts=opts.TitleOpts(title="冰属性"),
            visualmap_opts=opts.VisualMapOpts(type_="size", max_=150, min_=20),
            xaxis_opts=opts.AxisOpts(axislabel_opts={"rotate": 45})
        )
    )
    return c


def I():
    role_things = pd.read_excel("C:/Users/YHT/Desktop/项目/原神各属性角色信息.xlsx", header=0, index_col=0)
    role_things = role_things.fillna(axis=0, method="ffill")
    print(role_things)
    return_things = FindType("风").find_type()
    df = return_things.drop(["属性", "突破加成"], axis=1)
    Name = df["角色"]
    Hp = df["生命值"]
    Def = df["防御力"]
    Atk = df["攻击力"]
    c = (
        Scatter()
        .add_xaxis(list(Name))
        .add_yaxis("生命值", list(Hp))
        .add_yaxis("防御力", list(Def))
        .add_yaxis("攻击力", list(Atk))
        .set_global_opts(
            toolbox_opts=ToolboxOpts(is_show=True),
            title_opts=opts.TitleOpts(title="风属性"),
            visualmap_opts=opts.VisualMapOpts(type_="size", max_=150, min_=20),
            xaxis_opts=opts.AxisOpts(axislabel_opts={"rotate": 45})
        )
    )
    return c


def K():
    role_things = pd.read_excel("C:/Users/YHT/Desktop/项目/原神各属性角色信息.xlsx", header=0, index_col=0)
    role_things = role_things.fillna(axis=0, method="ffill")
    print(role_things)
    return_things = FindType("雷").find_type()
    df = return_things.drop(["属性", "突破加成"], axis=1)
    Name = df["角色"]
    Hp = df["生命值"]
    Def = df["防御力"]
    Atk = df["攻击力"]
    c = (
        Scatter()
        .add_xaxis(list(Name))
        .add_yaxis("生命值", list(Hp))
        .add_yaxis("防御力", list(Def))
        .add_yaxis("攻击力", list(Atk))
        .set_global_opts(
            toolbox_opts=ToolboxOpts(is_show=True),
            title_opts=opts.TitleOpts(title="雷属性"),
            visualmap_opts=opts.VisualMapOpts(type_="size", max_=150, min_=20),
            xaxis_opts=opts.AxisOpts(axislabel_opts={"rotate": 45})
        )
    )
    return c


page = Page(layout=Page.DraggablePageLayout)
page.add(a(), b(), c(), d(), x(), y(), z(), e(), f(), g(), h(), I(), K())
# page.render(".html")
# Page.save_resize_html(".html", cfg_file=".json", dest="./templates/.html")

在运行page.render("x.html")代码之后,会得到一个名为x的html文件,打开x.html文件,将图例排版、保存,会得到一个json文件。

再运行Page.save_resize_html("x.html", cfg_file="********.json", dest="./templates/*******.html")之后,会得到最后的页面。(此处文件名已用*号代替)

运行结果:(第一个图像是3D柱状图)

相关推荐
AI视觉网奇17 分钟前
Detected at node ‘truediv‘ defined at (most recent call last): Node: ‘truediv‘
人工智能·python·tensorflow
GuYue.bing39 分钟前
网络下载ts流媒体
开发语言·python
牛顿喜欢吃苹果1 小时前
linux创建虚拟串口
python
-Mr_X-1 小时前
FFmpeg在python里推流被处理过的视频流
python·ffmpeg
-芒果酱-1 小时前
KNN分类算法 HNUST【数据分析技术】(2025)
分类·数据挖掘·数据分析
一个不秃头的 程序员1 小时前
代码加入SFTP JAVA ---(小白篇3)
java·python·github
susu10830189111 小时前
python实现根据搜索关键词爬取某宝商品信息
爬虫·python
喜欢猪猪2 小时前
Java技术专家视角解读:SQL优化与批处理在大数据处理中的应用及原理
android·python·adb
海绵波波1072 小时前
flask后端开发(1):第一个Flask项目
后端·python·flask
林的快手2 小时前
209.长度最小的子数组
java·数据结构·数据库·python·算法·leetcode