回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我目前正在绘制一个包含大量分类数据的堆积条形图,并且只希望显示传说中的重要物种(在~500个物种中,我希望显示~25个)。有什么简单的方法可以做到这一点吗?下面是我的代码:</p>
<pre><code>labels=['0','20','40','60','80','100','120']
ax1=subj1df.plot(kind='barh', stacked=True,legend=True,cmap='Paired', grid=False)
legend(ncol=2,loc=2, bbox_to_anchor=(1.05, 1), borderaxespad=0.)
label1=['Baseline','8h','24h','48h','96h','120h']
ax1.set_yticklabels(label1, fontdict=None, minor=False)
plt.title('Subject 1 Phyla',fontweight='bold')
plt.savefig('Subject1Phyla.eps', format='eps', dpi=1000)
ax1.set_xticklabels(labels)
</code></pre>
<p>编辑:尝试添加此项以仅显示一个图例项,但仅返回空图例:</p>
<pre><code>h, l = ax1.get_legend_handles_labels()
legend(l[4],h[4],ncol=2,loc=2, bbox_to_anchor=(1.05, 1), borderaxespad=0.)
</code></pre>