如何添加将“四分位数”中值更改为“平均值”线以显示图形

2024-06-06 22:38:42 发布

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

我有下面的小提琴图和相关的inner=“quartile”值,我更改了行格式。 The image of my previous graph, that I want to have the final form on the same format, but with -The median line (middle) changed with the mean value line of each plot-

在不同的帖子中,我计算了将平均值添加到小提琴图中,然而,它们是以圆点形式出现的,正如我在下图中所指出的,我已经浏览并搜索了函数点图的使用源代码,但是,我无法找到将圆点更改为通过每个小提琴图的线条的方法https://seaborn.pydata.org/generated/seaborn.pointplot.html

我正在编写的代码是一个很长的代码,但以下是允许我分享的相关部分: 我们从大学文件中导出数据,并将其存储在由3个元素组成的数组中,其中数组的3个索引中的每一个都是由100行逗号分隔的数组数据。3个数据数组的合并数组称为{brain_parts}brain_part,其中brain_parts是用户在下面的变量“brain_parts_we_have”中输入的所有可能选项的动态名称

import numpy as np
import pandas as pd
from matplotlib.patches import PathPatch
import seaborn as sns
import matplotlib.pyplot as plt
from numpy import mean

brain_parts_we_have = ("A","B","C","D","E")
test_conditions = ("b","d","e")

violin_graph = sns.violinplot(  data= globals()["{brain_parts}_brain_part".format(brain_parts = letter.upper() ) ] , inner=None, estimator=mean, scale="width" ,palette = my_pal, )
     
sns.pointplot(data= globals()["{brain_parts}_brain_part".format(brain_parts = letter.upper() ) ], estimator=mean , linestyles=' ' , join=True, ci = None)

for l in violin_graph.lines:
    #print("first")
    #print(l)
    l.set_linestyle('-')
    l.set_linewidth(0.8) ## Sets the thickness of the quartile lines 
    l.set_color('white') ## Sets the color of the quartile lines 
    l.set_alpha(0.8)
for l in violin_graph.lines[1::3]:
    #print("second")
    #print(l)
    l.set_linestyle('-')
    l.set_linewidth(1.2) ## Sets the thickness of the mean lines 
    l.set_color('black') ## Sets the color of the mean lines 
    l.set_alpha(0.8)

    

我的图形的图像

下面的帖子都没有回答我的问题,我知道如何添加四分位线,但它们显示的是中位数;我想用一条平均线来改变中间线

在Seaborn小提琴图上绘制附加分位数(1个答案) Quartiles line properties in seaborn violinplot 如何在同一图形中使用seaborn pointplot和violinplot?(更改点图的标记)(2个答案) How to use seaborn pointplot and violinplot in the same figure? (change xticks and marker of pointplot) seaborn violinplot中的四分位数线特性(1个答案) Plot Additional Quantiles on Seaborn Violin Plots


Tags: oftheinimportas数组seabornmean