如何为具有不同比例数据的不同类别显示单个小提琴图?

2024-09-24 20:31:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Python的Seaborn库来可视化我的数据集。当我在一个绘图中绘制所有类的数据时,绘图显示不正确,这可能是因为所有类可能没有相同比例的数据(如下所示)

Violin plot with all classes together

但是,当我绘制单个类的数据时,它会正确显示(如图所示)

Violin plot with a single class

我应该在相同的尺度上标准化所有类的数据,然后再次绘图,还是有其他方法来实现所有类的单一小提琴绘图

谢谢你的帮助

编辑:

按照@warlax56的要求,我在代码中做了如下操作:

import seaborn as sb
import pandas as pd
import matplotlib.pyplot as plt

# Global settings for Seaborn library
sb.set_style("whitegrid", {
    "grid.linestyle": '--'
})


def main():
    # The location of Gaussian Pre-processing data for both age and BMI
    # that gives the highest accuracy for 0.56s and 0.36s SD respectively
    age_feats_file = '../Data/SVM-RFE-N36-gaussian-age-sigma100.csv'

    # Load the Age csv file
    age_data = pd.read_csv(age_feats_file)

    # plotting only f50 for checking
    vplot = sb.violinplot(x='age_class', y='f50', data=age_data, inner="box")
    vplot.set_xticklabels(vplot.get_xticklabels(), rotation=20)
    plt.show()

SVM-RFE-N36-gaussian-age-sigma100.csv是包含下图所示数据的数据集csv文件:

Dataset


Tags: csv数据import绘图foragedataas