• 03 pyechars 直角坐标系图表(示例代码+效果图)


    目录

    1.Bar柱状图/条形图

    2 Line折线图

    3 Scatter散点图

    4 EffectScatter涟漪特效散点图

    5 Boxplot箱型图

    6 Kline k线图

    7 HeatMap热力图

    8 PictorialBar象型柱状图

    9 overlap层叠图

    9.1 Overlap_bar_line

    9.2 Overlap_line_scatter

    Faker中函数的介绍:


    1.Bar柱状图/条形图

    1. """
    2. 学习中遇到问题没人解答?小编创建了一个Python学习交流QQ群:732481539
    3. 寻找有志同道合的小伙伴,互帮互助,群里还有不错的视频学习教程和PDF电子书!
    4. """
    5. # 柱状图/条形图
    6. from pyecharts.charts import Bar
    7. x_data = ["语文", "数学", "英语", "生物", "物理", "化学"] # x轴数据 数据必须是字符串
    8. y_data = [114, 95, 107, 81, 85, 87] # y轴数据 数据必须是整数或者小数
    9. bar = Bar() # 初始化图表
    10. bar.add_xaxis(x_data) # x轴
    11. bar.add_yaxis('成绩', y_data) # y轴
    12. bar.render("bar.html") # 渲染html文件

    2 Line折线图

    1. # 折线图
    2. from pyecharts.charts import Line
    3. x_data = ['1月', '2月', '3月', '4月', '5月', '6月'] # x轴数据 数据必须是字符串
    4. y_data = [1123, 1153, 1089, 1207, 1298, 1123] # y轴数据 数据必须是整数或者小数
    5. line = Line() # 初始化图表
    6. line.add_xaxis(x_data) # x轴
    7. line.add_yaxis('月消费', y_data) # y轴
    8. line.render("line.html") # 渲染html文件

    3 Scatter散点图

    1. # 散点图
    2. from pyecharts.charts import Scatter
    3. x_data = ['1月', '2月', '3月', '4月', '5月', '6月'] # x轴数据
    4. y_data = [1123, 1153, 1089, 1207, 1298, 1123] # y轴数据
    5. scatter = Scatter() # 初始化图表
    6. scatter.add_xaxis(x_data) # x轴
    7. scatter.add_yaxis('月消费', y_data) # y轴
    8. scatter.render("scatter.html") # 渲染html文件

    4 EffectScatter涟漪特效散点图

    1. from pyecharts.charts import EffectScatter
    2. x_data = ['1月', '2月', '3月', '4月', '5月', '6月'] # x轴数据
    3. y_data = [1123, 1153, 1089, 1207, 1298, 1123] # y轴数据
    4. effectScatter = EffectScatter()
    5. effectScatter.add_xaxis(x_data) # x轴
    6. effectScatter.add_yaxis('月消费', y_data) # y轴
    7. effectScatter.render("effectScatter.html") # 渲染html文件

    5 Boxplot箱型图

    1. # 箱型图
    2. from pyecharts.charts import Boxplot
    3. import random
    4. x_data = ['A', 'B', 'C', 'D', 'E', 'F']
    5. y_data = [[random.randint(100, 200) for i in range(10)] for item in x_data] #[[164, 102, 161, 106, 144, 186, 197, 186, 196, 125], [158, 131, 143, 111, 110, 175, 109, 107, 104, 153], [163, 174, 182, 142, 134, 158, 113, 149, 176, 183], [198, 142, 182, 125, 105, 149, 171, 122, 105, 156], [146, 126, 100, 164, 149, 117, 118, 170, 138, 155], [177, 110, 119, 178, 126, 164, 131, 176, 195, 134]]
    6. print(y_data)
    7. Boxplot = Boxplot()
    8. Boxplot.add_xaxis(x_data) # x轴
    9. Boxplot.add_yaxis('', Boxplot.prepare_data(y_data)) # y轴
    10. Boxplot.render("Boxplot.html") # 渲染html文件

    6 Kline k线图

    1. # k线图
    2. from pyecharts.charts import Kline
    3. date_list = ["2022/6/{}".format(i + 1) for i in range(30)]
    4. y_data = [
    5. [2320.26, 2320.26, 2287.3, 2362.94],
    6. [2300, 2291.3, 2288.26, 2308.38],
    7. [2295.35, 2346.5, 2295.35, 2345.92],
    8. [2347.22, 2358.98, 2337.35, 2363.8],
    9. [2360.75, 2382.48, 2347.89, 2383.76],
    10. [2383.43, 2385.42, 2371.23, 2391.82],
    11. [2377.41, 2419.02, 2369.57, 2421.15],
    12. [2425.92, 2428.15, 2417.58, 2440.38],
    13. [2411, 2433.13, 2403.3, 2437.42],
    14. [2432.68, 2334.48, 2427.7, 2441.73],
    15. [2430.69, 2418.53, 2394.22, 2433.89],
    16. [2416.62, 2432.4, 2414.4, 2443.03],
    17. [2441.91, 2421.56, 2418.43, 2444.8],
    18. [2420.26, 2382.91, 2373.53, 2427.07],
    19. [2383.49, 2397.18, 2370.61, 2397.94],
    20. [2378.82, 2325.95, 2309.17, 2378.82],
    21. [2322.94, 2314.16, 2308.76, 2330.88],
    22. [2320.62, 2325.82, 2315.01, 2338.78],
    23. [2313.74, 2293.34, 2289.89, 2340.71],
    24. [2297.77, 2313.22, 2292.03, 2324.63],
    25. [2322.32, 2365.59, 2308.92, 2366.16],
    26. [2364.54, 2359.51, 2330.86, 2369.65],
    27. [2332.08, 2273.4, 2259.25, 2333.54],
    28. [2274.81, 2326.31, 2270.1, 2328.14],
    29. [2333.61, 2347.18, 2321.6, 2351.44],
    30. [2340.44, 2324.29, 2304.27, 2352.02],
    31. [2326.42, 2318.61, 2314.59, 2333.67],
    32. [2314.68, 2310.59, 2296.58, 2320.96],
    33. [2309.16, 2286.6, 2264.83, 2333.29],
    34. [2282.17, 2263.97, 2253.25, 2286.33],
    35. ]
    36. kline = (Kline()
    37. .add_xaxis(date_list)
    38. .add_yaxis('', y_data)
    39. )
    40. kline.render("kline.html") # 渲染html文件

    7 HeatMap热力图

    1. # 热力图
    2. from pyecharts.charts import HeatMap
    3. import random
    4. data = [[i, j, random.randint(0, 100)] for i in range(24) for j in range(7)]
    5. hour_list = [str(i) for i in range(24)]
    6. week_list = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
    7. heat = (HeatMap()
    8. .add_xaxis(hour_list)
    9. .add_yaxis("", week_list, data)
    10. )
    11. heat.render("heat.html")

    8 PictorialBar象型柱状图

    1. # 象型图
    2. from pyecharts.charts import PictorialBar
    3. x_data = ['1月', '2月', '3月', '4月', '5月', '6月'] # x轴数据
    4. y_data = [1123, 1153, 1089, 1207, 1298, 1123] # y轴数据
    5. pictorialBar = PictorialBar() # 初始化图表
    6. pictorialBar.add_xaxis(x_data) # x轴
    7. pictorialBar.add_yaxis('月消费', y_data) # y轴
    8. pictorialBar.render("pictorialBar .html") # 渲染html文件

    9 overlap层叠图

    9.1 Overlap_bar_line

    1. # 层叠图Overlap_bar_line
    2. from pyecharts.charts import Bar
    3. from pyecharts.charts import Line
    4. x_data = ['1月', '2月', '3月', '4月', '5月', '6月']
    5. y_data_bar = [1123, 1153, 1089, 1207, 1298, 1123]
    6. y_data_line = [1300, 1200, 1100, 1400, 1500, 1200]
    7. bar = (Bar()
    8. .add_xaxis(x_data)
    9. .add_yaxis('', y_data_bar)
    10. )
    11. line = (Line()
    12. .add_xaxis(x_data)
    13. .add_yaxis('', y_data_line)
    14. )
    15. overlap = bar.overlap(line)
    16. overlap.render("overlap_bar_line .html")

    9.2 Overlap_line_scatter

    1. # 层叠图 Overlap_line_scatter
    2. from pyecharts import options as opts
    3. from pyecharts.charts import Line, Scatter
    4. from pyecharts.faker import Faker
    5. x = Faker.choose()
    6. line = (
    7. Line()
    8. .add_xaxis(x)
    9. .add_yaxis("商家A", Faker.values())
    10. .add_yaxis("商家B", Faker.values())
    11. .set_global_opts(title_opts=opts.TitleOpts(title="Overlap-line+scatter"))
    12. )
    13. scatter = (
    14. Scatter()
    15. .add_xaxis(x)
    16. .add_yaxis("商家A", Faker.values())
    17. .add_yaxis("商家B", Faker.values())
    18. )
    19. line.overlap(scatter)
    20. line.render("overlap_line_scatter.html")

     Faker.values() 详解:生成7个随机整数,这7个随机整数一般是两位数和三位数的组合

    Faker中函数的介绍:

    class _Faker:
        clothes = ["衬衫", "毛衣", "领带", "裤子", "风衣", "高跟鞋", "袜子"]
        drinks = ["可乐", "雪碧", "橙汁", "绿茶", "奶茶", "百威", "青岛"]
        phones = ["小米", "三星", "华为", "苹果", "魅族", "VIVO", "OPPO"]
        fruits = ["草莓", "芒果", "葡萄", "雪梨", "西瓜", "柠檬", "车厘子"]
        animal = ["河马", "蟒蛇", "老虎", "大象", "兔子", "熊猫", "狮子"]
        cars = ["宝马", "法拉利", "奔驰", "奥迪", "大众", "丰田", "特斯拉"]
        dogs = ["哈士奇", "萨摩耶", "泰迪", "金毛", "牧羊犬", "吉娃娃", "柯基"]
        week = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
        week_en = "Saturday Friday Thursday Wednesday Tuesday Monday Sunday".split()
        clock = (
            "12a 1a 2a 3a 4a 5a 6a 7a 8a 9a 10a 11a 12p "
            "1p 2p 3p 4p 5p 6p 7p 8p 9p 10p 11p".split()
        )
        visual_color = [
            "#313695",
            "#4575b4",
            "#74add1",
            "#abd9e9",
            "#e0f3f8",
            "#ffffbf",
            "#fee090",
            "#fdae61",
            "#f46d43",
            "#d73027",
            "#a50026",
        ]
        months = ["{}月".format(i) for i in range(1, 13)]
        provinces = ["广东", "北京", "上海", "江西", "湖南", "浙江", "江苏"]
        guangdong_city = ["汕头市", "汕尾市", "揭阳市", "阳江市", "肇庆市", "广州市", "惠州市"]
        country = [
            "China",
            "Canada",
            "Brazil",
            "Russia",
            "United States",
            "Africa",
            "Germany",
        ]
        days_attrs = ["{}天".format(i) for i in range(30)]
        days_values = [random.randint(1, 30) for _ in range(30)]

  • 相关阅读:
    PostgreSQL数据库统计信息——analyze统计信息收集
    微服务的好处(优点)有哪些?
    是面试官放水,还是实在公司太缺人?这都没挂,阿里巴巴原来这么容易进...
    C程序函数调用&系统调用
    Java注解
    编译原理复习——文法和语言
    面试算法25:链表中的数字相加
    自动驾驶学习笔记(三)——场景设计
    Arthas热替换java的class文件
    如何将极狐GitLab 漏洞报告导出为 HTML 或 PDF 格式或导出到 Jira
  • 原文地址:https://blog.csdn.net/c_lanxiaofang/article/details/126021659