目录
AttributeError: 'numpy.ndarray' object has no attribute 'fill_betweenx'
计划棘突布局为4行2列,这样实际上轴的索引应该是双下标,既要指定行还要指定列。
使用subplots可视化多个基于标签分组的小提琴图;
此处的错误在于axs[index]
正确的应该是第一幅图为axs[0,0],第二幅图为axs[0,1],第三幅图为axs[1,0]
以此类推。
- f, axs = plt.subplots(4,2,figsize=(10,30))
-
- #
-
- columns = ['a1','b1','a2','b2','a3','b3','a4','b4']
-
- for index,col in enumerate(columns):
- print(index)
- sns.violinplot(x=df.label, y=df[col],ax=axs[index])
-
- f.tight_layout()
因为要使用循环、所以干脆把子图设置为8行1列
- f, axs = plt.subplots(8,1,figsize=(10,30))
-
- #
-
- columns = ['a1','b1','a2','b2','a3','b3','a4','b4']
-
- for index,col in enumerate(columns):
- print(index)
- sns.violinplot(x=df.label, y=df[col],ax=axs[index])
-
- f.tight_layout()
AttributeError Traceback (most recent call last)
4 # make scatterplot with legends
5 for index,col in enumerate(eda_columns):
----> 6 sns.violinplot(x=df.label, y=df[col],ax=axs[index])
7
8 f.tight_layout()
D:\anaconda\lib\site-packages\seaborn\_decorators.py in inner_f(*args, **kwargs)
44 )
45 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
---> 46 return f(**kwargs)
47 return inner_f
48
D:\anaconda\lib\site-packages\seaborn\categorical.py in violinplot(x, y, hue, data, order, hue_order, bw, cut, scale, scale_hue, gridsize, width, inner, split, dodge, orient, linewidth, color, palette, saturation, ax, **kwargs)
2403 ax = plt.gca()
2404
-> 2405 plotter.plot(ax)
2406 return ax
2407
D:\anaconda\lib\site-packages\seaborn\categorical.py in plot(self, ax)
1041 def plot(self, ax):
1042 """Make the violin plot."""
-> 1043 self.draw_violins(ax)
1044 self.annotate_axes(ax)
1045 if self.orient == "h":
D:\anaconda\lib\site-packages\seaborn\categorical.py in draw_violins(self, ax)
759 def draw_violins(self, ax):
760 """Draw the violins onto `ax`."""
--> 761 fill_func = ax.fill_betweenx if self.orient == "v" else ax.fill_between
762 for i, group_data in enumerate(self.plot_data):
763
AttributeError: 'numpy.ndarray' object has no attribute 'fill_betweenx'