• AttributeError: ‘numpy.ndarray‘ object has no attribute ‘fill_betweenx‘


    AttributeError: 'numpy.ndarray' object has no attribute 'fill_betweenx'

    目录

    AttributeError: 'numpy.ndarray' object has no attribute 'fill_betweenx'

    问题:

    解决:

    完整错误:


    问题:

    计划棘突布局为4行2列,这样实际上轴的索引应该是双下标,既要指定行还要指定列。

    使用subplots可视化多个基于标签分组的小提琴图;

    此处的错误在于axs[index]

    正确的应该是第一幅图为axs[0,0],第二幅图为axs[0,1],第三幅图为axs[1,0]

    以此类推。

    1. f, axs = plt.subplots(4,2,figsize=(10,30))
    2. #
    3. columns = ['a1','b1','a2','b2','a3','b3','a4','b4']
    4. for index,col in enumerate(columns):
    5. print(index)
    6. sns.violinplot(x=df.label, y=df[col],ax=axs[index])
    7. f.tight_layout()

    解决:

    因为要使用循环、所以干脆把子图设置为8行1列

    1. f, axs = plt.subplots(8,1,figsize=(10,30))
    2. #
    3. columns = ['a1','b1','a2','b2','a3','b3','a4','b4']
    4. for index,col in enumerate(columns):
    5. print(index)
    6. sns.violinplot(x=df.label, y=df[col],ax=axs[index])
    7. f.tight_layout()

    完整错误:

    AttributeError                            Traceback (most recent call last)
    in
          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'

  • 相关阅读:
    STC51单片机学习笔记3——C语言流水灯
    8.11-分析工具、8.12-数据字典、8.13-数据流图 8.14-设计工具
    echarts柱状图的背景动态效果
    idea搭建ssm项目全过程详解:
    classification_report
    LeetCode每日两题02:轮转数组 (均1200道)
    为什么多数情况下GPT-3.5比LLaMA 2更便宜?
    JDBC-环境搭建及简单介绍和使用
    1. 刷题——数组
    通过深度可分离卷积神经网络对七种表情进行区分
  • 原文地址:https://blog.csdn.net/zhongkeyuanchongqing/article/details/126412911