25.Python可视化-Pyecharts

Python可视化-Pyecharts实验

In:

pip install pyecharts

In:

import pyecharts

In:

from pyecharts.faker import Faker
from pyecharts import options as opts

In:

Faker.cars

out:

['宝马', '法拉利', '奔驰', '奥迪', '大众', '丰田', '特斯拉']

In:

Faker.values()

out:

[82, 72, 44, 126, 131, 101, 142]

In:

#柱状图
from pyecharts.charts import Bar
bar = Bar().add_xaxis(Faker.cars)\
           .add_yaxis("京东",Faker.values())\
           .add_yaxis("天猫",Faker.values())\
           .set_global_opts(title_opts=\
                           opts.TitleOpts(title="汽车"))
# bar.render("yinliao.html")
bar.render_notebook()

out:

D:\ProgramData\Anaconda3\lib\site-packages\pyecharts\charts\chart.py:14: PendingDeprecationWarning: pyecharts 所有图表类型将在 v1.9.0 版本开始强制使用 ChartItem 进行数据项配置 :)
  super().__init__(init_opts=init_opts)
<script>
    require.config({
        paths: {
            'echarts':'https://assets.pyecharts.org/assets/echarts.min'
        }
    });
</script>
    <div id="bdf4f5c6e94d4698b7149b18bd9e357b" style="width:900px; height:500px;"></div>
<script>
        require(['echarts'], function(echarts) {
                var chart_bdf4f5c6e94d4698b7149b18bd9e357b = echarts.init(
                    document.getElementById('bdf4f5c6e94d4698b7149b18bd9e357b'), 'white', {renderer: 'canvas'});
                var option_bdf4f5c6e94d4698b7149b18bd9e357b = {
    "animation": true,
    "animationThreshold": 2000,
    "animationDuration": 1000,
    "animationEasing": "cubicOut",
    "animationDelay": 0,
    "animationDurationUpdate": 300,
    "animationEasingUpdate": "cubicOut",
    "animationDelayUpdate": 0,
    "color": [
        "#c23531",
        "#2f4554",
        "#61a0a8",
        "#d48265",
        "#749f83",
        "#ca8622",
        "#bda29a",
        "#6e7074",
        "#546570",
        "#c4ccd3",
        "#f05b72",
        "#ef5b9c",
        "#f47920",
        "#905a3d",
        "#fab27b",
        "#2a5caa",
        "#444693",
        "#726930",
        "#b2d235",
        "#6d8346",
        "#ac6767",
        "#1d953f",
        "#6950a1",
        "#918597"
    ],
    "series": [
        {
            "type": "bar",
            "name": "\u4eac\u4e1c",
            "legendHoverLink": true,
            "data": [
                27,
                81,
                59,
                148,
                25,
                40,
                42
            ],
            "showBackground": false,
            "barMinHeight": 0,
            "barCategoryGap": "20%",
            "barGap": "30%",
            "large": false,
            "largeThreshold": 400,
            "seriesLayoutBy": "column",
            "datasetIndex": 0,
            "clip": true,
            "zlevel": 0,
            "z": 2,
            "label": {
                "show": true,
                "position": "top",
                "margin": 8
            }
        },
        {
            "type": "bar",
            "name": "\u5929\u732b",
            "legendHoverLink": true,
            "data": [
                120,
                140,
                74,
                145,
                89,
                124,
                29
            ],
            "showBackground": false,
            "barMinHeight": 0,
            "barCategoryGap": "20%",
            "barGap": "30%",
            "large": false,
            "largeThreshold": 400,
            "seriesLayoutBy": "column",
            "datasetIndex": 0,
            "clip": true,
            "zlevel": 0,
            "z": 2,
            "label": {
                "show": true,
                "position": "top",
                "margin": 8
            }
        }
    ],
    "legend": [
        {
            "data": [
                "\u4eac\u4e1c",
                "\u5929\u732b"
            ],
            "selected": {
                "\u4eac\u4e1c": true,
                "\u5929\u732b": true
            },
            "show": true,
            "padding": 5,
            "itemGap": 10,
            "itemWidth": 25,
            "itemHeight": 14
        }
    ],
    "tooltip": {
        "show": true,
        "trigger": "item",
        "triggerOn": "mousemove|click",
        "axisPointer": {
            "type": "line"
        },
        "showContent": true,
        "alwaysShowContent": false,
        "showDelay": 0,
        "hideDelay": 100,
        "textStyle": {
            "fontSize": 14
        },
        "borderWidth": 0,
        "padding": 5
    },
    "xAxis": [
        {
            "show": true,
            "scale": false,
            "nameLocation": "end",
            "nameGap": 15,
            "gridIndex": 0,
            "inverse": false,
            "offset": 0,
            "splitNumber": 5,
            "minInterval": 0,
            "splitLine": {
                "show": false,
                "lineStyle": {
                    "show": true,
                    "width": 1,
                    "opacity": 1,
                    "curveness": 0,
                    "type": "solid"
                }
            },
            "data": [
                "\u5b9d\u9a6c",
                "\u6cd5\u62c9\u5229",
                "\u5954\u9a70",
                "\u5965\u8fea",
                "\u5927\u4f17",
                "\u4e30\u7530",
                "\u7279\u65af\u62c9"
            ]
        }
    ],
    "yAxis": [
        {
            "show": true,
            "scale": false,
            "nameLocation": "end",
            "nameGap": 15,
            "gridIndex": 0,
            "inverse": false,
            "offset": 0,
            "splitNumber": 5,
            "minInterval": 0,
            "splitLine": {
                "show": false,
                "lineStyle": {
                    "show": true,
                    "width": 1,
                    "opacity": 1,
                    "curveness": 0,
                    "type": "solid"
                }
            }
        }
    ],
    "title": [
        {
            "text": "\u6c7d\u8f66",
            "padding": 5,
            "itemGap": 10
        }
    ]
};
                chart_bdf4f5c6e94d4698b7149b18bd9e357b.setOption(option_bdf4f5c6e94d4698b7149b18bd9e357b);
        });
    </script>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值