【发布时间】:2018-01-30 21:37:21
【问题描述】:
我正在尝试使用此代码创建radar chart:
import matplotlib.pyplot as plt
import numpy as np
import sys
import pandas as pd
from math import pi
import seaborn as sns
import cv2
tab1 = np.random.rand(21)
#Experiment
tab1 =[(-10)*x for x in tab1]
# ------- PART 1: Create background
# number of variable
cell_lines = range(0,22)
N = len(range)
# What will be the angle of each axis in the plot? (we divide the plot / number of variable)
angles = [n / float(N) * 2 * pi for n in range(N)]
angles += angles[:0]
# Initialise the spider plot
ax = plt.subplot(111, polar=True)
# If you want the first axis to be on top:
ax.set_theta_offset(pi / 6)
ax.set_theta_direction(-1)
# Draw one axe per variable + add labels labels yet
plt.xticks(angles[0:], cell_lines, fontsize=20,fontname="Arial",fontweight='bold',linespacing=0)
x=(3,6,9)
plt.yticks(x,fontsize=20, fontweight='bold',fontname="Arial",linespacing=0)
# Draw ylabels
ax.set_rlabel_position(0)
#plt.ylabel("%", fontsize=16)
#plt.title("STUFF", fontsize=20, fontweight='bold', linespacing=2)
# ------- PART 2: Add plots
# Plot each individual = each line of the data
# I don't do a loop, because plotting more than 3 groups makes the chart unreadable
#print(control)
# Ind1
#values=df.loc[0].drop('control').values.flatten().tolist()
#values += values[:1]
#ax.plot(angles, control, linewidth=5, linestyle='solid', label="control")
#ax.fill(angles, control, 'b', alpha=0.1)
ax.plot(angles, tab1, linewidth=5, linestyle='solid', label="tab1", color='blue')
ax.fill(angles, tab1, 'b', alpha=0.1)
# Add legend
plt.legend(loc='upper right', bbox_to_anchor=(0.1, 0.1), fontsize=20)
plt.show()
使用此代码,我希望能够反转 r 轴,以便最外圈为 0,最内圈为 1。我不知道如何继续执行此操作。即使我将整个数据集乘以-1,然后绘制图表(就像我在experiment 评论下方所做的那样),数据看起来也更加偏斜,并且缺少所有内圈。有没有一种简单的方法可以让我只取法线图并反转轴?
【问题讨论】:
-
您是否尝试过像这样反转您的角度列表:“angles.reverse()”?
-
注意
cell_lines使代码无法重现。 -
糟糕,我已对其进行了编辑,以便重现。
标签: python matplotlib plot