绘图杂记【7】echarts / python 雷达图
发布日期:2021-05-07 22:36:41 浏览次数:10 分类:精选文章

本文共 7982 字,大约阅读时间需要 26 分钟。

在这里插入图片描述

option = {       title : {           text: '雷达图',        subtext: '卖山楂啦prss',        textStyle: {   				color: '#000000',				fontSize: 20,			}    },    tooltip : {           trigger: 'axis'    },    legend: {           orient : 'vertical',        x : 'right',        y : '50',        data:['英雄1','英雄2'],        itemWidth:30,//图例的宽度        itemHeight:10,//图例的高度        color:['#C1232B','#B5C334'],        textStyle:{   //图例文字的样式            color:'#000000',            fontSize:17        }    },    //修改图例颜色    color:['#D2CBF1','#F1C3C3'],    toolbox: {           show : true,        feature : {               dataView : {   show: true},            restore : {   show: true},            saveAsImage : {                   pixelRatio: 15}        }    },        //////////////////////////////////////////////////////    radar : [       {              indicator : [               {    text: '技能1', max: 6000},               {    text: '技能2', max: 16000},               {    text: '技能3', max: 30000},               {    text: '技能4', max: 38000},               {    text: '技能5', max: 52000},               {    text: '技能6', max: 25000}            ],                     splitArea : {                    show : true,                     areaStyle : {                          color: ['#FFFFFF', '#EEEEEE','#FFFFFF', '#EEEEEE', '#FFFFFF',]                         // 图表背景网格的颜色                   }         },         splitLine : {                  show : true,               lineStyle : {                      width : 1,                   color : ['#EEEEEE','#EEEEEE']                     // 图表背景网格线的颜色                }            },                    //半径             radius: 190,             // 坐标系起始角度,也就是第一个指示器轴的角度。[ default: 90 ]         startAngle: 90,         // 指示器名称和指示器轴的距离。[ default: 15 ]         nameGap: 15,         name: {               formatter: '{value}',            textStyle: {                   fontSize: 18,                color: '#000000' // 文字颜色            }        },         shape: 'circle',                    // 雷达图绘制类型,支持 'polygon'(多边形) 和 'circle'(圆)。[ default: 'polygon' ]	     splitNumber: 5,                     // (这里是圆的环数)指示器轴的分割段数。[ default: 5 ]            axisLine: {                            // (圆内的几条直线)坐标轴轴线相关设置	            lineStyle: {   	                color: '#000000',                   // 坐标轴线线的颜色。	                width: 0.15,                      	 // 坐标轴线线宽。	                type: 'solid',                   // 坐标轴线线的类型。	            }	        },        }    ],        ///////////////////////////////////////////////    calculable : true,    series : [        {               name: '',            type: 'radar',            data : [                {                       value : [4300, 10000, 28000, 35000, 50000, 19000],                    name : '英雄1',                    symbol: 'circle',                   // 单个数据标记的图形。	            symbolSize: 5,                      // 单个数据标记的大小,可以设置成诸如 10 这样单一的数字,也可以用数组分开表示宽和高,例如 [20, 10] 表示标记宽为20,高为10。	            label: {                       // 单个拐点文本的样式设置                            	                    normal: {     	                        show: true,             // 单个拐点文本的样式设置。[ default: false ]	                        position: 'top',        // 标签的位置。[ default: top ]	                        distance: 5,            // 距离图形元素的距离。当 position 为字符描述值(如 'top'、'insideRight')时候有效。[ default: 5 ]	                        color: '#4B4B4B',          // 文字的颜色。如果设置为 'auto',则为视觉映射得到的颜色,如系列色。[ default: "#fff" ]	                        fontSize: 8,           // 文字的字体大小	                        formatter:function(params) {     	                            return params.value;  	                        }  	                    }  	                },	                	           lineStyle: {                   // 单项线条样式。	                normal: {   	                    opacity: 0.1            // 图形透明度	                }	            },	            areaStyle: {                   // 单项区域填充样式	                normal: {   	                     opacity: 0.3,	                    color: 'rgba(255,0,0,0.6)'       // 填充的颜色。[ default: "#000" ]	                }}                                                        },                 {                       value : [3000, 14000, 18000, 11000, 42000, 11000],                    name : '英雄2',                    symbol: 'circle',                   // 单个数据标记的图形。	            symbolSize: 5,                      // 单个数据标记的大小,可以设置成诸如 10 这样单一的数字,也可以用数组分开表示宽和高,例如 [20, 10] 表示标记宽为20,高为10。	            	            // 加标签	            label: {                       // 单个拐点文本的样式设置                            	                    normal: {     	                        show: true,             // 单个拐点文本的样式设置。[ default: false ]	                        position: 'top',        // 标签的位置。[ default: top ]	                        distance: 5,            // 距离图形元素的距离。当 position 为字符描述值(如 'top'、'insideRight')时候有效。[ default: 5 ]	                        color: '#4B4B4B',          // 文字的颜色。如果设置为 'auto',则为视觉映射得到的颜色,如系列色。[ default: "#fff" ]	                        fontSize: 8,           // 文字的字体大小	                        formatter:function(params) {     	                            return params.value;  	                        }  	                    }  	                },	                	                	                	                lineStyle: {   	                normal: {   	                    opacity: 0.1	                }	            },	            areaStyle: {   	                normal: {   	                    opacity: 0.3,	                    color: 'rgba(51,0,255,0.5)'	                }	            }                }                                                            ]        }    ]};

在这里插入图片描述

数据

在这里插入图片描述

import matplotlibimport matplotlib.pyplot as plt import numpy as npimport pandas as pd# matplotlib.style.use('ggplot')matplotlib.rcParams['font.family']='SimHei'           matplotlib.rcParams['font.sans-serif']=['SimHei']data_labels=np.array(['英雄1','英雄2','英雄3'])n=6radar_labels=np.array(['    技能1','技能2','技能3',\                     '技能4   ','技能5','技能6'])    data = np.array(pd.read_clipboard()) angles=np.linspace(0,2*np.pi,6,endpoint=False) #将360度平均分为n个部分(有endpoint=False分为6个部分,反之5个部分)angles=np.concatenate((angles,[angles[0]]))plt.figure(facecolor='white')plt.subplot(111,polar=True)plt.figtext(0.52,0.95,'雷达图',ha='center',size=20)  # 设定线条和点的类型形状Linestyle = ['bo-','r+:','gD--']# Linestyle = ['bo-','r+:','gD--','yv-.','kp-']# 设定填充的颜色Fillcolor = ['b','r','g']Fillcolor = ['b','r','g','y','k']for i in range(3):    data1 = np.concatenate((data[i],[data[i][0]]))    plt.plot(angles,data1,Linestyle[i],linewidth=0.5)     plt.fill(angles,data1,facecolor=Fillcolor[i],alpha=0.1)legend=plt.legend(data_labels,loc=(0.94,0.94),labelspacing=0.1)plt.setp(legend.get_texts(),fontsize='small') plt.thetagrids(angles*180/np.pi,radar_labels)     plt.grid(True)    #打开坐标网格plt.ylim(0, 10)plt.show()plt.savefig(r'C:\Users\Administrator\Desktop\p1.png',dpi=500)

在这里插入图片描述

数据
在这里插入图片描述)

import matplotlibimport matplotlib.pyplot as plt import numpy as npimport pandas as pdmatplotlib.rcParams['font.family']='SimHei'           matplotlib.rcParams['font.sans-serif']=['SimHei']data_labels=np.array(['英雄1','英雄2','英雄3'])n=6radar_labels=np.array(['    技能1','技能2','技能3',\                     '技能4   ','技能5','技能6'])    data = np.array(pd.read_clipboard()) data = np.concatenate((data, [data[0]]))    angles=np.linspace(0,2*np.pi,n,endpoint=False)angles=np.concatenate((angles,[angles[0]]))     plt.figure(facecolor='white')plt.subplot(111,polar=True)plt.figtext(0.52,0.95,'雷达图',ha='center',size=20)  plt.thetagrids(angles*180/np.pi,radar_labels)sam = ['r-', 'o-.', 'g--', 'b-.', 'p:']plt.plot(angles,data,'o-',linewidth=1.5,alpha=0.2) #连线,画出不规则六边形plt.fill(angles,data,alpha=0.15) legend=plt.legend(data_labels,loc=(0.94,0.80),labelspacing=0.1)plt.setp(legend.get_texts(),fontsize='small')      plt.grid(True)plt.ylim(0, 10)plt.show()plt.savefig(r'C:\Users\Administrator\Desktop\p1.png',dpi=500)
上一篇:关于echarts导出图片分辨率问题
下一篇:利用 Python 爬取“工商秘密”微博,看看大家都在关注些什么?

发表评论

最新留言

路过按个爪印,很不错,赞一个!
[***.219.124.196]2025年03月24日 13时41分16秒