In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use matplotlib in Python to make radar maps for comparative analysis, which has a certain reference value. Interested friends can refer to it. I hope you will gain a lot after reading this article. Let the editor take you to know it.
Preface
The background of the radar map is like radar, using polygons to show the size of the data. I think it is more suitable for situations with many different dimensions, and it is a good tool to find the gap.
Among them, "persistence" is related to the number of days of learning, "amount of learning" is related to the number of lectures or reading, "notes" is related to the number and interaction of notes, "knowledge sharing" is related to the number of sharing and forwarding, and "curiosity" is related to the number and breadth of searches.
As can be seen from the picture, at the beginning of 2020, I was still weak in notes. Through hard work, the number of notes I took increased significantly.
With the help of radar map, we can see the gap intuitively, and then improve it better through analysis.
02
Next, let's take a look at the specific steps of drawing with matplotlib.
First, import the required libraries, set Chinese fonts, define colors, and so on.
# Import the required library import numpy as npimport pandas as pdimport matplotlib as mplimport matplotlib.pyplot as pltimport matplotlib.image as image# to display the Chinese label mpl.rcParams ['font.sans-serif'] = [' SimHei'] # automatically adapt to the layout mpl.rcParams.update ({'figure.autolayout': True}) # normal display negative sign mpl.rcParams [' axes.unicode_minus'] = False# disable scientific counting pd.set_option ('display.float_format' Lambda x:'% .2f'% x) # define colors Main color: blue, auxiliary color: grey, complementary color: orange c = {'blue':'# 00589F', 'dark blue':'# 003867', 'light blue':'# 5D9BCFR', 'gray':'# 99999999', 'dark gray':'# 666666', 'light gray':'# CCCCCC', 'orange':'# F68F00F00', 'dark orange':'# A05D00', 'light orange':'# FBC171'}
Second, read the data from the Excel file and define the data used for drawing.
# data source path filepath='./data/ Lin Ji's credit composition. Xlsx'# read the Excel file df = pd.read_excel (filepath) # extract the data needed for drawing data0 = df.iloc [0,2:]. Valuesdata1 = df.iloc [1,2:] .values # extract tag label = np.array (df.iloc [1,2:] .index) # tag for I that adds ratings according to scores D in enumerate (data1): if d > 4: grade ='A ^ + 'elif d = = 4: grade =' A' elif d > 3: grade ='B^ + 'elif d = = 3: grade =' B' else: grade ='B^-'label [I] +'\ n' + rang $\ bf {'+ grade +'} $'# data has several data The whole circle is divided into several parts angle = np.linspace (0, 2*np.pi, len (data0), endpoint=False) # add the first angle to all angle to achieve a closed angles = np.concatenate ((angle, [angle [0]])) # reverse order, so that the radar map shows clockwise angles = angles [::-1] # add the first data to all data To close data0 = np.concatenate ((data0, [data0 [0]])) data1 = np.concatenate ((data1, [data1 [0]]))
Next, start drawing with an "object-oriented" approach.
# drawing using the "object-oriented" method Define the size of the picture fig, ax=plt.subplots (figsize= (8,8), subplot_kw=dict (polar=True)) # set the background color fig.set_facecolor ('w') ax.set_facecolor ('w') # set the title ax.set_title ('\ nLin Ji's credit composition and its changes\ n\ npicture, fontsize=26, loc='left', color=c ['dark gray']) # set the grid tag ax.set_thetagrids (angles*180/np.pi Labels=label) # drawing radar map Use clockwise display of ax.plot (angles, data0, 'Omura, label=df.iloc [0,0] .strftime ('% Ymurf% mmurf% d')) ax.plot (angles, data1, 'oMuthur, label=df.iloc [1,0] .strftime ('% Ymurt% mmurf% d')) # set the polar coordinate 0 °position ax.set_theta_zero_location ('N') # set the polar diameter range ax.set_rlim (0) 5) # fill color ax.fill (angles, data0, facecolor=c ['light blue'], alpha=0.6) ax.fill (angles, data1, facecolor=c ['light orange'], alpha=0.6) # set polar diameter label Put it in the middle of the first quadrant ax.set_rlabel_position (360360-360/len (data0) / 2) # set the location of the legend display l = ax.legend (ncol=2, loc='lower center', frameon=False, borderaxespad=-3) Fontsize=13) for text in l.get_texts (): text.set_color (c ['dark gray']) # text.set_size (13) # remove the outer black circle ax.spines ['polar'] .set_visible (False) # set the coordinate label font size and color ax.tick_params (labelsize=16, colors=c [' dark gray']) plt.show () 03
Radar has a good effect in showing multi-dimensional scores or performance, and is widely used in financial analysis and benchmarking.
In addition, in some games, there is also the ability to use radar pictures to show characters.
However, the radar map also has some shortcomings, including:
(1) if more than 2 sets of data are displayed in a radar chart, it will make the chart difficult to read.
(2) the number of variables should not be too large, otherwise the dense lines may make people miss the point.
(3) from the point of view of the accuracy of expressing data, the angle in polar coordinates is not as good as the position in Cartesian coordinates.
The same data, different people may come to different views, the choice of charts may also be different, we usually need to consider the following factors:
(1) analyze and extract the information
(2) Type of data to which it belongs
(3) the views you want to express
(4) the message you want to emphasize.
Many people have a misunderstanding in drawing, that is, they like to use the so-called skills and innovation to make complex charts that are difficult for people to understand, which runs counter to the purpose of the chart and should be avoided.
Thank you for reading this article carefully. I hope the article "how to use matplotlib to make radar map for comparative analysis in Python" shared by the editor will be helpful to everyone. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.