Is any change 'DisplayName' property in plot function?

232 ビュー (過去 30 日間)
Lef Lederer
Lef Lederer 2015 年 3 月 19 日
plot(x,y,'DisplayName',{'name1','name2','name3','name4'})
produce error
Error using plot
Value must be a string.
This shall produce this plot with curve names.
Is any change in 'DisplayName' property in plot function?
  1 件のコメント
Baptiste Contour
Baptiste Contour 2020 年 6 月 26 日
編集済み: Baptiste Contour 2020 年 6 月 26 日
Using 2020a
Names need to be a char:
plot(magic(4),'DisplayName',char({'name1','name2','name3','name4'}))
You still need to specify a minimum the legend afterwards to display it, eg:
legend('location', 'best');

サインインしてコメントする。

採用された回答

Mike Garrity
Mike Garrity 2015 年 3 月 19 日
When we were rebuilding all of the graphics objects as MATLAB Objects, we found they they had several different variations of code that parsed this cell array case. You'll find in older versions of MATLAB that some variations of this will work for some objects, but not for others.
We wanted to unify this code so that all of the objects worked the same way. That way you wouldn't have to learn the differences between the different objects. But we couldn't come up with one version that replicated all of the existing variations. This particular case was one of the casualties.
The simplest workaround here is to use the set command, because it works the same for all objects. In this case, the following should work in any version of MATLAB.
h = plot(magic(3));
set(h,{'DisplayName'},{'first';'second';'third'})
legend show
If you look carefully at this, you'll notice some important points.
  • The property name is also in a cell array.
  • The cell array of values is the same shape as the array of handles.
This is the canonical form of this cell array 'dealing' syntax. It's the one that the various plotting commands were trying to match. But most of them were slightly different from this.
  5 件のコメント
Prajwal Gowdru Shanthamurthy
Prajwal Gowdru Shanthamurthy 2021 年 4 月 13 日
Hey Mike,
How do I set the interpreter for the 'DisplayName' strings as latex ?
Thanks in advance!
Muhammad Sajid Haroon
Muhammad Sajid Haroon 2021 年 8 月 13 日
Hi, i think this will work for you..it work for me.
plot(gammadB,PcovM,':+b','DisplayName','coverage','linewidth',2,'markersize',9);
h1= legend('location', 'best');
set(h1,'Interpreter','latex');
set(h1,'FontSize',32);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by