分享

python数据可视化简单实例

 hdzgx 2019-12-28
#                                python数据可视化笔记by skyliuhc```python
  1. #画条状图
  2. from pyecharts import Bar
  3. bar =Bar("example chart1","副标题")
  4. bar.add("成绩",["高数","大物","c语言","信号与系统"],[92,88,60,85])
  5. bar.show_config()#打印输出图表的所有配置
  6. bar.render()
  7. #然后去到这个代码所在的文件夹里面找到render.html点开他就有图了,下同
```
    {
        "title": [
            {
                "text": "example chart1",
                "subtext": "\u526f\u6807\u9898",
                "left": "auto",
                "top": "auto",
                "textStyle": {
                    "color": "#000",
                    "fontSize": 18
                },
                "subtextStyle": {
                    "color": "#aaa",
                    "fontSize": 12
                }
            }
        ],
        "toolbox": {
            "show": true,
            "orient": "vertical",
            "left": "95%",
            "top": "center",
            "feature": {
                "saveAsImage": {
                    "show": true,
                    "title": "\u4e0b\u8f7d\u56fe\u7247"
                },
                "restore": {
                    "show": true
                },
                "dataView": {
                    "show": true
                }
            }
        },
        "series_id": 8559168,
        "tooltip": {
            "trigger": "item",
            "triggerOn": "mousemove|click",
            "axisPointer": {
                "type": "line"
            },
            "formatter": null,
            "textStyle": {
                "color": "#fff",
                "fontSize": 14
            },
            "backgroundColor": "rgba(50,50,50,0.7)",
            "borderColor": "#333",
            "borderWidth": 0
        },
        "series": [
            {
                "type": "bar",
                "name": "\u6210\u7ee9",
                "data": [
                    92,
                    88,
                    60,
                    85
                ],
                "stack": "",
                "barCategoryGap": "20%",
                "label": {
                    "normal": {
                        "show": false,
                        "position": "top",
                        "textStyle": {
                            "color": "#000",
                            "fontSize": 12
                        },
                        "formatter": null
                    },
                    "emphasis": {
                        "show": true,
                        "position": null,
                        "textStyle": {
                            "color": "#fff",
                            "fontSize": 12
                        }
                    }
                },
                "markPoint": {
                    "data": []
                },
                "markLine": {
                    "data": []
                },
                "seriesId": 8559168
            }
        ],
        "legend": [
            {
                "data": [
                    "\u6210\u7ee9"
                ],
                "selectedMode": "multiple",
                "show": true,
                "left": "center",
                "top": "top",
                "orient": "horizontal",
                "textStyle": {
                    "fontSize": 12,
                    "color": "#333"
                }
            }
        ],
        "backgroundColor": "#fff",
        "xAxis": [
            {
                "name": "",
                "show": true,
                "nameLocation": "middle",
                "nameGap": 25,
                "nameTextStyle": {
                    "fontSize": 14
                },
                "axisLabel": {
                    "interval": "auto",
                    "rotate": 0,
                    "margin": 8,
                    "textStyle": {
                        "fontSize": 12,
                        "color": "#000"
                    }
                },
                "axisTick": {
                    "alignWithLabel": false
                },
                "inverse": false,
                "position": null,
                "boundaryGap": true,
                "min": null,
                "max": null,
                "data": [
                    "\u9ad8\u6570",
                    "\u5927\u7269",
                    "c\u8bed\u8a00",
                    "\u4fe1\u53f7\u4e0e\u7cfb\u7edf"
                ],
                "type": "category"
            }
        ],
        "yAxis": [
            {
                "name": "",
                "show": true,
                "nameLocation": "middle",
                "nameGap": 25,
                "nameTextStyle": {
                    "fontSize": 14
                },
                "axisLabel": {
                    "formatter": "{value} ",
                    "rotate": 0,
                    "interval": "auto",
                    "margin": 8,
                    "textStyle": {
                        "fontSize": 12,
                        "color": "#000"
                    }
                },
                "axisTick": {
                    "alignWithLabel": false
                },
                "inverse": false,
                "position": null,
                "boundaryGap": true,
                "min": null,
                "max": null,
                "splitLine": {
                    "show": true
                },
                "type": "value"
            }
        ],
        "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",
            "#f6f5ec"
        ]
    }




                                          柱状图数据堆叠和三维图
  1. ```python
  2. # encoding: utf-8
  3. #学完上述的简单例子之后让我们再练一个比较难的例子
  4. #这个例子涉及到一个网页显示多个图用page
  5. from pyecharts import Bar, Scatter3D
  6. from pyecharts import Page
  7. page = Page() # step 1
  8. # bar
  9. attr = ["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"]
  10. v1 = [5, 20, 36, 10, 75, 90]
  11. v2 = [10, 25, 8, 60, 20, 80]
  12. bar = Bar("柱状图数据堆叠示例")
  13. bar.add("商家A", attr, v1, is_stack=True)#is_stack表示是否对叠在一起
  14. bar.add("商家B", attr, v2, is_stack=True)
  15. page.add(bar) # step 2
  16. # scatter3D
  17. import random
  18. data = [[random.randint(0, 100), random.randint(0, 100), random.randint(0, 100)] for _ in range(80)]
  19. range_color = ['#313695', '#4575b4', '#74add1', '#abd9e9', '#e0f3f8', '#ffffbf',
  20. '#fee090', '#fdae61', '#f46d43', '#d73027', '#a50026']
  21. scatter3D = Scatter3D("3D 散点图示例", width=1200, height=600)
  22. scatter3D.add("", data, is_visualmap=True, visual_range_color=range_color)
  23. page.add(scatter3D) # step 2
  24. page.render() # step 3


```


标记线和标记点实例
```python
  1. from pyecharts import Bar
  2. bar=Bar("标记线和标记点实例")
  3. attr=["1","2","3","4","5","6"]
  4. v1 = [5, 20, 36, 10, 75, 90]
  5. v2 = [10, 25, 8, 60, 20, 80]
  6. bar.add("charcter1",attr,v1,mark_point=["average"])#对于charcter1标出其平均值
  7. bar.add("charater2",attr,v2,mark_line=["min","max"])#对于charcter2标出其最大,最小
  8. bar.render()
 x轴和y轴互换
```python
  1. from pyecharts import Bar
  2. bar=Bar("x轴和y轴互换")
  3. bar.add("character1",attr,v1,mark_line=["min","max"])
  4. bar.add("character2",attr,v2,is_convert=True,mark_line=["min","max"])
  5. bar.render('sb.html')#网页你也是可以换名字,默认是render.html
  6. #render 的英文意思有使成为这样就不难理解这个命令了

 带有涟漪特效的散点图

```python

  1. from pyecharts import EffectScatter
  2. v1=[10,20,30,40,50,60]
  3. v2=[10,20,30,40,50,60]
  4. es=EffectScatter("动态散点演示")
  5. es.add("散点图",v1,v2)
  6. es.render('scatter.html')
 动态散点图各种图形
``python
  1. from pyecharts import EffectScatter
  2. es=EffectScatter("动态散点图各种图形实例")
  3. es.add("1",[10],[10],symbol_size=10,effect_scale=3.5,effect_period=3,symbol="pin")#大头针
  4. es.add("2",[60],[60],symbol_size=15,effect_scale=3.5,effect_period=4,symbol="rect")#矩形
  5. es.add("3",[20],[20],symbol_size=20,effect_scale=4.5,effect_period=5,symbol="roundRect")#圆边矩形
  6. es.add("4",[30],[30],symbol_size=15,effect_scale=5.5,effect_period=6,effect_brushtype='fill',symbol="diamond")#钻石
  7. es.add("5",[40],[40],symbol_size=15,effect_scale=6.5,effect_period=7,symbol="arrow")#弓形
  8. es.add("6",[50],[50],symbol_size=15,effect_scale=5.5,effect_period=8,symbol="triangle")#三角形
  9. es.render('dynamics_catter.html')
 漏斗图

```python

  1. from pyecharts import Funnel
  2. attr=["美女","房子","车子","事业","家人","娱乐","数码产品"]
  3. value=[80,90,50,100,150,40,180]
  4. funnel=Funnel("男人心漏斗图")
  5. funnel.add("因素",attr,value,is_label_show=True,label_pos="inside",label_text_color="#fff")
  6. funnel.render('funnerl.html')```

    仪表盘

```python
  1. from pyecharts import Gauge#(Gauge计量表)
  2. gauge=Gauge("仪表盘实例","大作业怎么办啊啊啊")
  3. gauge.add("大作业","进度",10.00)
  4. gauge.render('gauge.html')
 折线图
```python
  1. from pyecharts import Line
  2. line=Line("折线图实例","不想学习")
  3. attr=["1","2","3","4","5","6"]
  4. v1 = [5, 20, 36, 10, 75, 90]
  5. v2 = [10, 25, 8, 60, 20, 80]
  6. line.add("charcter1",attr,v1,mark_point=["average"])#折线连接
  7. line.add("charater2",attr,v2,is_smooth=True,mark_line=["min","max"])#平滑的曲线
  8. line.render('line.html')
 折线-阶梯图
```python
  1. from pyecharts import Line
  2. line=Line("折线图——阶梯实例","就是不想学习")
  3. attr=["1","2","3","4","5","6"]
  4. v1 = [5, 20, 36, 10, 75, 90]
  5. v2 = [10, 25, 8, 60, 20, 80]
  6. line.add("charcter1",attr,v1,is_step=True,is_label_show=True,mark_point=["average"])#折线连接+阶梯
  7. line.add("charater2",attr,v2,is_smooth=True,mark_line=["min","max"])#平滑的曲线
  8. line.render('line_step.html')
```
 折线-面积图    

```python
  1. from pyecharts import Line
  2. line=Line("折线图——面积实例","老子就是不想学习")
  3. attr=["1","2","3","4","5","6"]
  4. v1 = [5, 20, 36, 10, 75, 90]
  5. v2 = [10, 25, 8, 60, 20, 80]
  6. line.add("charcter1",attr,v1,is_fill=True,line_opacity=0.2,area_opacity=0.4,area_color='yellow',is_label_show=True,)#opacity 不透明度
  7. line.add("charater2",attr,v2,is_fill=True,line_opacity=0.8,area_opacity=0.2,area_color='green',is_smooth=True,)#平滑的曲线
  8. line.render('line_fill.html')
```
  水球图
```python
  1. from pyecharts import Liquid
  2. liquid=Liquid("水球图实例","我想玩吃鸡")
  3. liquid.add("Liquid",[0.8])
  4. liquid.render('liquid.html')
```
 饼图

```python

  1. from pyecharts import Pie
  2. attr=["吃鸡","lol","今日头条","qq","朋友圈","不想学习的时间又不玩手机"]
  3. v1=[1,1,1,0.5,0.3,6]
  4. pie=Pie("饼图实例/咸鱼")
  5. pie.add("大饼",attr,v1,is_label_show=True)
  6. pie.render('pie.html')
```
  雷达图
```python
  1. from pyecharts import Radar
  2. schema=[("打人",7976),("骂人",16000),("咬人",30000),("捶人",38000),("恶心人",52000),("恨人",25000)]
  3. v1=[[4300,10000,28000,35000,50000,19000]]
  4. v2=[[0,0,0,0,0,0]]
  5. radar=Radar("benben和chunchun对比")
  6. radar.config(schema)
  7. radar.add("chunchun",v1,is_splitLine=True,label_color=['blue'],is_axisline_show=True)
  8. radar.add("benben",v2,label_color=['red'],is_area_show=False)
  9. radar.render('radar.html')

图形效果

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约