(5)所有角色数据分析页面的构建-5

所有角色数据分析页面,包括一个时间轴柱状图、六个散点图、六个柱状图(每个属性角色的生命值/防御力/攻击力的max与min的对比)。

python 复制代码
"""绘图"""
from pyecharts.charts import Timeline
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(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(
            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(
            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(
            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(
            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(
            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(
            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(
            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(
            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(
            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(
            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(
            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(
            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="chaonfig.json", dest="./templates/无.html")

运行结果:

相关推荐
Python大数据分析@3 分钟前
python操作CSV和excel,如何来做?
开发语言·python·excel
黑叶白树4 分钟前
简单的签到程序 python笔记
笔记·python
Shy96041817 分钟前
Bert完形填空
python·深度学习·bert
上海_彭彭28 分钟前
【提效工具开发】Python功能模块执行和 SQL 执行 需求整理
开发语言·python·sql·测试工具·element
3345543236 分钟前
element动态表头合并表格
开发语言·javascript·ecmascript
沈询-阿里40 分钟前
java-智能识别车牌号_基于spring ai和开源国产大模型_qwen vl
java·开发语言
zhongcx0144 分钟前
使用Python查找大文件的实用脚本
python
残月只会敲键盘1 小时前
面相小白的php反序列化漏洞原理剖析
开发语言·php
ac-er88881 小时前
PHP弱类型安全问题
开发语言·安全·php
ac-er88881 小时前
PHP网络爬虫常见的反爬策略
开发语言·爬虫·php