How do I change the marker size for a plot?

3,354 ビュー (過去 30 日間)
john birt
john birt 2011 年 4 月 30 日
編集済み: DGM 2024 年 11 月 19 日 20:52
Im trying to set the marker size on a plot but having no luck, heres my code this works fine plot( x , x^2,'-k*',... x , x^3,'-ko',... x , x^4,'-k' ) but when i try and set marker size it does not plot( x , x^2,'-k*',... x , x^3,'-ko','MarkerSize',12,... x , x^4,'-k' ) what do I need to do?
  1 件のコメント
Evan
Evan 2023 年 1 月 18 日
type 'LineWidth' instead of 'MarkerSize'

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

採用された回答

Oleg Komarov
Oleg Komarov 2024 年 11 月 13 日 0:00
編集済み: MathWorks Support Team 2024 年 11 月 13 日 4:26
You can change the marker size for a line plot by setting the “MarkerSize” property, either as a name-value pair or by accessing the “Line” object. Name-value pair: If you set this property as a name-value pair with the “plot” function, you must set it after all the x,y pairs. Name-value pair settings apply to all the plotted lines. To use a different marker size for each line, use separate “plot” commands. For example: plot(x,x^2,'-k*', 'MarkerSize',20) hold on plot(x,x^3,'-ko','MarkerSize',12) plot(x,x^4,'-k' ) hold off Accessing the “Line” object: Alternatively, return the “Line” objects as an output argument from the “plot” function and then set the “MarkerSize” property for each object separately. p = plot(x,x^2,'-k*', x,x^3,'-ko', x,x^4,'-k' ) p(1).MarkerSize = 20; p(2).MarkerSize = 12;
  5 件のコメント
Yoon Choi
Yoon Choi 2024 年 11 月 19 日 15:25
marker shape
DGM
DGM 2024 年 11 月 19 日 20:49
編集済み: DGM 2024 年 11 月 19 日 20:52
Well, normally I'd run this, but I guess that doesn't work either now.
% some fake data
x = 0:10;
y1 = x.^1.5;
y2 = x.^1.6;
% plot it by specifying combined marker and line style
hp1 = plot(x,y1,'o:'); hold on
% plot it by specifying marker style alone
hp2 = plot(x,y2,'marker','square')
% if you want to change the marker style, you can
% these are the supported values for the 'marker' property
set(hp2,'marker')

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

その他の回答 (3 件)

Jan
Jan 2011 年 4 月 30 日
plot(x, x^2,'-k*');
hold('on');
plot(x, x^3,'-ko','MarkerSize', 12);
plot(x, x^4,'-k');
  2 件のコメント
Leo Simon
Leo Simon 2014 年 5 月 22 日
For some obscure reason, MarkerSize is not consistently used. When you use scatter, you need to set 'SizeData' instead of 'MarkerSize'. Also, the scale of SizeData is different from that of MarkerSize' E.g.,
h = scatter(rand,rand,'b','filled'); set(h,'SizeData',96);
Michelle Hirsch
Michelle Hirsch 2016 年 1 月 29 日
The difference is subtle, but intentional. It stems from the different use cases.
MarkerSize is used to control the overall size of markers, just like the overall width of a line with LineWidth or font size. The units are in points, just like LineWidth.
Scatter is used to actually scale the marker sizes based on data. Specifically, the area of the marker is proportional to the value. This is why the units are in points squared.

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


Matt Fig
Matt Fig 2011 年 4 月 30 日
To make this type of thing much easier, you could download this code so that all these options are available from a simple mouse click:
  3 件のコメント
Michelle Hirsch
Michelle Hirsch 2016 年 1 月 29 日
You can also enable a context menu for changing line and marker properties just by enabling plot edit mode. Click on the button in the Figure toolbar with an arrow on it, then right click on your line.
Frank Pierce
Frank Pierce 2016 年 9 月 1 日
yes

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


Hari Desanur
Hari Desanur 2016 年 11 月 15 日
The Marker Size property for a particular line can be set using line object handles. For example -
l = plot(x1,y1,'*-',x2,y2,'*-');
l(1).MarkerSize = 8; % set marker size of 8 for the first line (x1,y1)
l(2).MarkerSize = 12;
  1 件のコメント
P_L
P_L 2019 年 4 月 18 日
Hi there and what if you wanted to chnage the colours of 'ko' data points so that they are filled for example with 'b'
Many thanks

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

カテゴリ

Help Center および File ExchangeFormatting and Annotation についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by