File Exchange Pick of the Week

Our best user submissions

Multi-column legend, revisited

Jiro‘s Pick this week is the NumColumns property of the legend function, new as of R2018a.

This week, R2019a was released. This is another exciting release with many new features and capabilities. Read and learn about them here (note that this page will always show the latest features from the latest release, so depending on when you read this, you may get a page for other than R2019a).

So why am I talking about a feature from R2018a? There are two reasons.

  1. The NumColumns property of legend allows you to create a multi-column legend, which happened to be a topic of a previous Pick of the Week post, “Create Multi-Column Plot Legends” by Brett. columnlegend by Simon is still a good entry to have in your utility belt if you are using R2017b or older, but if you have newer releases, you can now do that with the legend function.
  2. We were looking at some web traffic analytics, and we found out that the Pick of the Week post I mentioned above kept getting a lot of traffic even after 8 years. That meant that there were probably a lot of people wanting to create multi-column legends, and they were landing on the blog post. For those people, I wanted to make sure that they knew about the new feature, in addition to the File Exchange entry.

So, let’s just see the new legend functionality in action.

t = 0:pi/64:3*pi;
dPhi = pi/16;
set(gca,'LineStyleOrder',{'-','--',':','-.'})
hold on
for ii = 1:18
    plot(t,sin(t+dPhi*ii))
    legend_str{ii} = num2str(ii);
end
ylim([-1.15 1.6])

legend(legend_str,'Location','NorthWest','NumColumns',6)

Comments

Give it a try and let us know what you think here. And, you can probably expect future posts highlighting some new R2019a features.




Published with MATLAB® R2018b

|
  • print

Comments

To leave a comment, please click here to sign in to your MathWorks Account or create a new one.