2017-02-14 194 views
2

我想在Python中做一個雷達圖,但我不知道該怎麼做。我在網上閱讀了一些教程,其中大部分都非常複雜(繪製多邊形,計算放置點,...)。Python的雷達圖/繪圖教程

所以我想知道是否有人有一個「簡單」的教程。我不想做一些非常非常非常簡單的事情。另外,如果有一個可以做到這一點的Python庫。我閱讀的所有教程都使用matplotlib,但這非常困難。我也發現圖書館「pychardir」,但我無法安裝它。

回答

7

首先啓動A應該在matplotlib網站的例子:pie_and_polar_charts example code: polar_bar_demo.py

如果您還有疑問,您可以隨時回來。同意:使用Python或matplotlib的很好的雷達圖例子很難找到。

這是我跑 enter image description here

# Plots a radar chart. 

from math import pi 
import matplotlib.pyplot as plt 


# Set data 
cat = ['Speed', 'Reliability', 'Comfort', 'Safety', 'Effieciency'] 
values = [90, 60, 65, 70, 40] 

N = len(cat) 

x_as = [n/float(N) * 2 * pi for n in range(N)] 

# Because our chart will be circular we need to append a copy of the first 
# value of each list at the end of each list with data 
values += values[:1] 
x_as += x_as[:1] 


# Set color of axes 
plt.rc('axes', linewidth=0.5, edgecolor="#888888") 


# Create polar plot 
ax = plt.subplot(111, polar=True) 


# Set clockwise rotation. That is: 
ax.set_theta_offset(pi/2) 
ax.set_theta_direction(-1) 


# Set position of y-labels 
ax.set_rlabel_position(0) 


# Set color and linestyle of grid 
ax.xaxis.grid(True, color="#888888", linestyle='solid', linewidth=0.5) 
ax.yaxis.grid(True, color="#888888", linestyle='solid', linewidth=0.5) 


# Set number of radial axes and remove labels 
plt.xticks(x_as[:-1], []) 

# Set yticks 
plt.yticks([20, 40, 60, 80, 100], ["20", "40", "60", "80", "100"]) 


# Plot data 
ax.plot(x_as, values, linewidth=0, linestyle='solid', zorder=3) 

# Fill area 
ax.fill(x_as, values, 'b', alpha=0.3) 


# Set axes limits 
plt.ylim(0, 100) 


# Draw ytick labels to make sure they fit properly 
for i in range(N): 
    angle_rad = i/float(N) * 2 * pi 

    if angle_rad == 0: 
     ha, distance_ax = "center", 10 
    elif 0 < angle_rad < pi: 
     ha, distance_ax = "left", 1 
    elif angle_rad == pi: 
     ha, distance_ax = "center", 1 
    else: 
     ha, distance_ax = "right", 1 

    ax.text(angle_rad, 100 + distance_ax, cat[i], size=10, horizontalalignment=ha, verticalalignment="center") 


# Show polar plot 
plt.show() 
+0

似乎是一個圓形barplot。據此,這個想法是做一個圓形的曲線圖。我仍然不明白每行代碼的目的是什麼(除了最後一個哈哈哈)。 – Biopy

+0

您想要的示例的圖片可能會有所幫助。 – Elmex80s

+0

就像這樣:http://www.qrb-bw.de/pdf_pool/pythondemo/cdpydoc/images/simpleradar.png甚至這個http://www.science-emergence.com/media/images/393.png 。我檢查了提供這些地塊的代碼,但它們很難理解 – Biopy