How do I combine legend entries for a spline and data points?

6 ビュー (過去 30 日間)
Stuart
Stuart 2012 年 10 月 16 日
コメント済み: jingyi lai 2021 年 2 月 17 日
I'm plotting a series of discrete data points and using a 'pchip' spline to create a smooth curve that passes through the points. In the legend I would like it to appear as a line with a marker and not as two separate entries. Is there a way to combine them into a single entry?
Thanks!

採用された回答

Matt Fig
Matt Fig 2012 年 10 月 16 日
編集済み: Matt Fig 2012 年 10 月 16 日
Here is an example:
% First set up the data and the spline fit plot.
x = -3:3;
y = [-1 -1 -1 0 1 1 1];
t = -3:.01:3;
p = pchip(x,y,t);
plot(x,y,'or',t,p,'-b')
L = legend('Fitted Data'); % Pass only final string.
% Now we can fix the legend.
H = findall(gcf,'marker','none','linestyle','none');
set(H,'linestyle','-','color',[0 0 1]);
set(L,'location','east')
  3 件のコメント
Nathaniel H Werner
Nathaniel H Werner 2019 年 6 月 27 日
I just ran this script from the answer in R2018b since I have a similar problem and it does not work. This is the final result. As you can see it still only labels the red dots in the legend when it should also have a blue line going through it as far as I understand the original question.
CombineLegend.png
jingyi lai
jingyi lai 2021 年 2 月 17 日
same question as Nathaniel

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSplines についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by