Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.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 如何在matplotlib中为条形图添加辅助标签?_Python_Pandas_Matplotlib_Bar Chart - Fatal编程技术网

Python 如何在matplotlib中为条形图添加辅助标签?

Python 如何在matplotlib中为条形图添加辅助标签?,python,pandas,matplotlib,bar-chart,Python,Pandas,Matplotlib,Bar Chart,我创建了以下函数来绘制绘图。我试图在这个图上添加第二层xticks。我检查了类似的问题,如,但此方法更改了数据帧以添加第二层标签。我不想这样做,因为我从一个非常大的数据集获取数据,很难调整绘制每个绘图的数据。我正在寻找一种更自动化的方法 def plotFun(means,errors,x_Names,x_label,pngPath, x_len=8, y_len=5): fig, ax = plt.subplots(figsize=(x_len,y_len))

我创建了以下函数来绘制绘图。我试图在这个图上添加第二层xticks。我检查了类似的问题,如,但此方法更改了数据帧以添加第二层标签。我不想这样做,因为我从一个非常大的数据集获取数据,很难调整绘制每个绘图的数据。我正在寻找一种更自动化的方法

def plotFun(means,errors,x_Names,x_label,pngPath, x_len=8, y_len=5):
        fig, ax = plt.subplots(figsize=(x_len,y_len))
        ax.set_yscale('log')
        xSize=len(means.index)
        means.plot.bar(yerr=errors, ax=ax, capsize=3, width = 0.65 ,edgecolor='black')
        plt.legend(bbox_to_anchor=(1.05, 1), loc='upper left', borderaxespad=0.)
        plt.tight_layout()
        plt.xlabel(x_label)
        plt.xticks(np.arange(xSize),x_Names , rotation=0)
        plt.savefig(pngPath, dpi=300, bbox_inches='tight', transparent=True)
        plt.show()
数据帧的平均值和误差如下所示:

File    A         B             C               D
1       2225.0    45981.6       1.301418e+06    48125.0
2       21751.0   28198700.0    1.202896e+09    3822348.0
3       62682.6   232038400.0   1.895988e+10    29267700.0
4       15966.0   2924685.0     2.650770e+08    2712005.0
5       112895.5  604058.5      2.117455e+06    53895.0
['Type 1': {'1','2','3'}, 'Type 2':{'4','5'}]
X_名称是

['1', '2', '3', '4','5']
我现在的情节是这样的

我想添加第二层标签,如下所示:

File    A         B             C               D
1       2225.0    45981.6       1.301418e+06    48125.0
2       21751.0   28198700.0    1.202896e+09    3822348.0
3       62682.6   232038400.0   1.895988e+10    29267700.0
4       15966.0   2924685.0     2.650770e+08    2712005.0
5       112895.5  604058.5      2.117455e+06    53895.0
['Type 1': {'1','2','3'}, 'Type 2':{'4','5'}]
在绘图上以两个级别显示,如:

1   2   3      4   5  

 Type 1       Type 2
有没有关于如何调整我的代码来做到这一点的想法?我不想调整数据帧。 谢谢

根据此问题(非常相似)matplotlib中的功能仍在wishlist中。

根据此问题(非常相似)matplotlib中的功能仍在wishlist中