Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 18615

Show only certain items in legend

$
0
0

I currently am plotting a stacked bar graph of a large amount of taxonomic data, and only wish to show significant species in the legend (out of ~500 I wish to show ~25). Is there a simple way to do this? Below is the code I have:

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)

Edit: tried adding this to show only one legend entry, however only returns an empty legend:

h, l = ax1.get_legend_handles_labels()legend(l[4],h[4],ncol=2,loc=2, bbox_to_anchor=(1.05, 1), borderaxespad=0.)

Viewing all articles
Browse latest Browse all 18615

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>