【问题标题】:factorplot main title overlaps sub titles in seabornfactorplot 主标题与 seaborn 中的子标题重叠
【发布时间】:2019-07-30 03:58:47
【问题描述】:

我制作了下面的图表。如您所见,主标题与图表的副标题重叠。我尝试了不同的方法,但似乎都没有奏效。我还附上了我的代码。

def save_multi_columns_categorical_charts(df, chart, columns, y, hue, title, single_statistic=False,
                                          single_statistic_name=None, kind='point', col='Message Size (Bytes)'):
    filename = chart + ".png"
    print("Creating chart: " + title + ", File name: " + filename)
    fig, ax = plt.subplots()
    all_columns = [col,'Back-end Service Delay (ms)', 'Concurrent Users','Scenario Name']
    all_columns.extend(columns)
    df_results = df[all_columns]

    df_results['new_var'] = df_results[col] + ' - ' + df_results['Scenario Name']


    g = sns.factorplot(x="Concurrent Users", y='Throughput (Requests/sec)',
                       hue='new_var', col='Back-end Service Delay (ms)',
                       data=df_results, kind=kind,
                       size=5, aspect=1, col_wrap=2, legend=False)



    plt.subplots_adjust(top=10, left=0.1)
    g.fig.suptitle(title,y=1.08)  # can also get the figure from plt.gcf()
    plt.legend(loc=2, frameon=True, title="Response Time Summary")

    plt.savefig(filename)
    plt.clf()
    plt.cla()
    plt.close(fig)

【问题讨论】:

  • 如果您将y=1.08 更改为g.fig.suptitle 会发生什么?您可能还需要调整topsubplots_adjust 中的间距

标签: python-3.x matplotlib plot formatting seaborn


【解决方案1】:

尝试给出标题与轴顶部的偏移量(以磅为单位),以便在主标题和底层图形之间添加一些间隙:

plt.title('剧情标题', pad=100)

不断增加焊盘值以根据需要调整间隙。

【讨论】:

    猜你喜欢
    • 2015-09-18
    • 2022-10-01
    • 1970-01-01
    • 2013-05-19
    • 2014-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多