首页 > 解决方案 > 子图过于紧凑

问题描述

我正在尝试使用 matplotlib 绘制三个图形,但图像的显示方式不清楚,我尝试使用plt.tight_layout()plt.subplots_adjust(left=0.1, bottom=0.1, right=0.5, top =1.0, wspace=0.5, hspace=0.5),但它们都不起作用。

我不太确定问题是我正在使用的IDE(Visual Studio Code),还是有任何方法可以绘制单曲图但在同一个python函数中。如果有人知道如何改进图表的显示方式。

def program_graph(year):
    ...
    fig,axes = plt.subplots(nrows=3, ncols = 1)
    risk_info_srv_evesa.plot.bar(ax = axes[0])
    risk_info_act_pln.plot.bar(ax = axes[1])
    final_db.plot.bar(ax = axes[2])
    axes[0].title.set_text('SRV-EVESOS per Program')
    axes[1].title.set_text('Action Plan per Program')
    axes[2].title.set_text('SRV-EVESOS Vs Action Plan')
    plt.tight_layout()
    plt.subplots_adjust(left=0.4, bottom=0.1, right=0.5, top=1.0, wspace=0.5, hspace=0.5)
    plt.show() 

我认为最好的解决方案是单独显示每个图表,但我不想为每个图表实现不同的功能。有谁知道如何解决这个问题?

在此处输入图像描述

标签: pythonpython-3.xpandasdataframematplotlib

解决方案


推荐阅读