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>