Matplotlib中的意外缺口箱线图,Seaborn中的错误

2024-10-17 02:32:37 发布

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

使用sklearn,并尝试使用matplotlib做一个方框图。你知道吗

nps = np.array(all_s)
npd = [dd for dd in all_d]
plt.boxplot(nps.T, npd)
plt.show()

enter image description here

但结果是有缺口的,上界或下界都很奇怪。另外,当我尝试在Seaborn中绘制它时,我得到以下错误:Buffer has wrong number of dimensions (expected 1, got 2) 我错过了什么?你知道吗

编辑:添加的数据

all_d = range(1,11)    

all_s =

    [[0.31111111111111112,
      0.38333333333333336,
      0.2722222222222222,
      0.29999999999999999,
      0.32222222222222224,
      0.32777777777777778,
      0.3888888888888889,
      0.36312849162011174,
      0.37430167597765363,
      0.37430167597765363],
     [0.57222222222222219,
      0.6333333333333333,
      0.6166666666666667,
      0.62777777777777777,
      0.68333333333333335,
      0.62777777777777777,
      0.69444444444444442,
      0.61452513966480449,
      0.6033519553072626,
      0.6033519553072626],
     [0.73333333333333328,
      0.82222222222222219,
      0.68888888888888888,
      0.7055555555555556,
      0.77777777777777779,
      0.73333333333333328,
      0.81666666666666665,
      0.73743016759776536,
      0.72625698324022347,
      0.72067039106145248],
     [0.81666666666666665,
      0.89444444444444449,
      0.87222222222222223,
      0.87777777777777777,
      0.87777777777777777,
      0.78888888888888886,
      0.85555555555555551,
      0.84916201117318435,
      0.84916201117318435,
      0.82681564245810057],
     [0.90555555555555556,
      0.93888888888888888,
      0.87777777777777777,
      0.91666666666666663,
      0.90555555555555556,
      0.87222222222222223,
      0.90555555555555556,
      0.88268156424581001,
      0.87709497206703912,
      0.8994413407821229],
     [0.89444444444444449,
      0.97222222222222221,
      0.83888888888888891,
      0.91666666666666663,
      0.89444444444444449,
      0.84444444444444444,
      0.92777777777777781,
      0.92737430167597767,
      0.8938547486033519,
      0.92178770949720668],
     [0.90555555555555556,
      0.96111111111111114,
      0.93888888888888888,
      0.91666666666666663,
      0.91666666666666663,
      0.90000000000000002,
      0.93333333333333335,
      0.95530726256983245,
      0.8994413407821229,
      0.92737430167597767],
     [0.90555555555555556,
      0.96111111111111114,
      0.92222222222222228,
      0.92222222222222228,
      0.91666666666666663,
      0.93888888888888888,
      0.93333333333333335,
      0.96648044692737434,
      0.92737430167597767,
      0.92737430167597767],
     [0.93333333333333335,
      0.97777777777777775,
      0.94999999999999996,
      0.93888888888888888,
      0.94444444444444442,
      0.97777777777777775,
      0.94999999999999996,
      0.98882681564245811,
      0.95530726256983245,
      0.94413407821229045],
     [0.91666666666666663,
      0.97777777777777775,
      0.94999999999999996,
      0.94444444444444442,
      0.92777777777777781,
      0.98333333333333328,
      0.94999999999999996,
      0.97765363128491622,
      0.96089385474860334,
      0.94413407821229045]]

Tags: informatplotlibshownppltsklearnall
2条回答

boxplot的第二个参数是notch。通过传递一个非空列表,您传递的是一个真值,因此会显示凹口。我不知道你在那里传递npd的意图是什么。你知道吗

我终于弄明白了!感谢BrenBarn指出.boxplot的第二个参数是notch。我做了以下工作:

nps = np.array(all_s)
npd = [dd for dd in all_d]
box=sns.boxplot(data=nps.T) 
box.set_xticklabels(npd)
plt.show()

enter image description here

相关问题 更多 >