繁体   English   中英

传奇色彩 spyder plot python

[英]legend color spyder plot python

来自以下示例数据集:

df_toy = pd.DataFrame({"Group":[1,2],
                   "Var1":[100,20],
                   "Var2":[50,40],
                   "Var3":[10,14],
                   "Var4":[10,140],
                   "Var5":[100,14]})

我正在通过以下代码绘制 spyder/polar plot:

variables = [col for col in df_toy.columns if col != "Group"]
labels= variables + [variables[0]]

np.random.seed(1)
angles = np.linspace(0, 2 * np.pi, len(variables), endpoint=False)

# The first value is repeated to close the chart.
angles=np.concatenate((angles, [angles[0]]))

# polar plot each row separately
for row in df_toy.values.tolist():
    values = row[1:] + [row[1]]
    plt.polar(angles, values, 'o-', linewidth=2)
    plt.fill(angles, values, alpha=0.25)

# Representation of the spider graph
plt.legend(df_toy["Group"])
plt.thetagrids(angles * 180 / np.pi, labels)
plt.show()

产生以下 plot,但是,图例和线条颜色之间存在错误的对应关系:

在此处输入图像描述

我做错了什么?

Label 绘图时的图例条目:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
...
...
# polar plot each row separately
for row in df_toy.values.tolist():
    values = row[1:] + [row[1]]
    plt.polar(angles, values, 'o-', linewidth=2, label=row[0])
    plt.fill(angles, values, alpha=0.25)

# Representation of the spider graph
plt.legend()
...

样本 output:

在此处输入图像描述

我没有重现你的问题:

import matplotlib.pyplot as plt

df_toy = pd.DataFrame({"Group":[1,2],
                   "Var1":[100,20],
                   "Var2":[50,40],
                   "Var3":[10,14],
                   "Var4":[10,140],
                   "Var5":[100,14]})

variables = [col for col in df_toy.columns if col != "Group"]
labels= variables + [variables[0]]

np.random.seed(1)
angles = np.linspace(0, 2 * np.pi, len(variables), endpoint=False)

# The first value is repeated to close the chart.
angles=np.concatenate((angles, [angles[0]]))

# polar plot each row separately
for row in df_toy.values.tolist():
    values = row[1:] + [row[1]]
    plt.polar(angles, values, 'o-', linewidth=2)
    plt.fill(angles, values, alpha=0.25)

# Representation of the spider graph
plt.legend(df_toy["Group"])
plt.thetagrids(angles * 180 / np.pi, labels)
plt.show()

output:

极坐标图

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM