Can I place markers on only some of the points of my line plot?

191 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2013 年 9 月 3 日
編集済み: MathWorks Support Team 2023 年 4 月 14 日
I have a plot that has a lot of points, and I would like to visualize it with markers. Placing markers on all the points makes the plot too cluttered; instead of a line made of markers I just get a thick line.
How can I plot only every other marker, or every third marker, or something like that?

採用された回答

MathWorks Support Team
MathWorks Support Team 2023 年 4 月 14 日
編集済み: MathWorks Support Team 2023 年 4 月 14 日
You can control the marker positions on a line plot using the 'MarkerIndices' property. With that, you can specify at which indices of the data points you want to display markers.
For example, let us create 1000 points ranging from 0 to 10, and create a sinusoidal function of increasing amplitude.
x = linspace(0,10,1000);
y = exp(x/10).*sin(4*x);
Now, let us plot the function with a solid line and add asterisk markers every tenth data points:
plot(x,y,'-*','MarkerIndices',1:10:length(y))
The result is the following:
You can find more information about creating a line plot with markers here:https://www.mathworks.com/help/matlab/creating_plots/create-line-plot-with-markers.html
  1 件のコメント
Oleg Komarov
Oleg Komarov 2016 年 2 月 3 日
Highly appreciated if implemented.

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

その他の回答 (1 件)

Nirajan R
Nirajan R 2016 年 9 月 24 日
編集済み: MathWorks Support Team 2021 年 12 月 30 日
The feature has been added now. You can use MarkerIndices property to achieve this. More info here: https://www.mathworks.com/help/matlab/creating_plots/create-line-plot-with-markers.html
  1 件のコメント
Steven Lord
Steven Lord 2019 年 6 月 4 日
When you call plot, omitting part of the data can change the shape of the line that is drawn so to control which markers are plotted you need to use MarkerIndices.
When you call scatter, omitting part of the data does not impact the rest of the points. Therefore you can simply call scatter on only part of your data. If you switch between the two figures created by the example below, the only differences will be the titles and the five points which were omitted in the second figure.
x = rand(1, 25);
y = rand(1, 25);
figure
scatter(x, y)
axis([0 1 0 1])
title('All data')
figure
scatter(x(1:20), y(1:20))
axis([0 1 0 1])
title('Only first 20 points')

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

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by