Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何在Seaborn FaceGrid中注释条形图(在FactoryPlot中工作)_Python 3.x_Matplotlib_Seaborn - Fatal编程技术网

Python 3.x 如何在Seaborn FaceGrid中注释条形图(在FactoryPlot中工作)

Python 3.x 如何在Seaborn FaceGrid中注释条形图(在FactoryPlot中工作),python-3.x,matplotlib,seaborn,Python 3.x,Matplotlib,Seaborn,我试图在4x4 Seaborn FaceGrid的每个绘图中为每个条叠加一个值。下面是一个Factorplot。如何修改它以在facetgrid中工作?针对g.axes.flat.patches似乎也不起作用 # Annotate a value into each bar in each plot (Doesn't work) # Error: AttributeError: 'numpy.flatiter' object has no attribute 'patches' f

我试图在4x4 Seaborn FaceGrid的每个绘图中为每个条叠加一个值。下面是一个Factorplot。如何修改它以在facetgrid中工作?针对g.axes.flat.patches似乎也不起作用

 # Annotate a value into each bar in each plot (Doesn't work)
 # Error: AttributeError: 'numpy.flatiter' object has no attribute 'patches'

    for p in g.axes.flat.patches:
        g.annotate("{:.1f}".format(p.get_height()) , 
                    (p.get_x() + p.get_width() / 2., p.get_height()-fudge), # Placement
                    ha='center', va='center', fontsize=12, color='white', rotation=0, xytext=(0, 20),
                    textcoords='offset points')
非常感谢

(下面是facetgrid的简化示例)


这是for循环代码,它将以facetgrid的每个绘图上的列为目标

    for ax in g.axes.ravel():

这是for循环代码,它将以facetgrid的每个绘图上的列为目标

    for ax in g.axes.ravel():
您可以使用:

for ax in g.axes.ravel():
  for p in ax.patches:
    ax.annotate(format(p.get_height(), '.2f'), (p.get_x() + p.get_width() / 2., p.get_height()), ha = 'center', va = 'center', xytext = (0, 10), textcoords = 'offset points')
您可以使用:

for ax in g.axes.ravel():
  for p in ax.patches:
    ax.annotate(format(p.get_height(), '.2f'), (p.get_x() + p.get_width() / 2., p.get_height()), ha = 'center', va = 'center', xytext = (0, 10), textcoords = 'offset points')
你能提供一个吗?你能提供一个吗?