擅长:python、mysql、java
<p>您可以在函数中放置打印线,并在for循环中调用它,在每次迭代中自动更改列、标题和轴:</p>
<pre><code>fig, axes =plt.subplots(2, 3, sharey=True)
fig.tight_layout(pad=3)
def plotting(column, title, ax):
df["outcomes"] = df[column].astype(OUTCOMES)
bpt=sns.countplot(x= "outcomes", data=df, palette='GnBu', ax=ax)
plt.setp(bpt.get_xticklabels(), rotation=60, size=6, ha='right')
bpt.set(xlabel='')
bpt.set_title(title)
columns = ['TS1', 'TS2', 'TS3', 'TS4', 'TS5']
titles = ['Testing 1', 'Testing 2', 'Testing 3', 'Testing 4', 'Testing 5']
for column, title, ax in zip(columns, titles, axes.flatten()):
plotting(column, title, ax)
axes[1,2].set_visible(False)
plt.show()
</code></pre>
<p><a href="https://i.stack.imgur.com/5bb2v.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5bb2v.png" alt="enter image description here"/></a></p>