【发布时间】: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会发生什么?您可能还需要调整top在subplots_adjust中的间距
标签: python-3.x matplotlib plot formatting seaborn