3,827 views (last 30 days)
Show older comments
john birt on 30 Apr 2011
-
-
Link
Direct link to this question
https://www.mathworks.com/matlabcentral/answers/6537-how-do-i-change-the-marker-size-for-a-plot
Commented: Evan on 18 Jan 2023
Accepted Answer: Oleg Komarov
Open in MATLAB Online
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 Comment Show -1 older commentsHide -1 older comments
Show -1 older commentsHide -1 older comments
Evan on 18 Jan 2023
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/6537-how-do-i-change-the-marker-size-for-a-plot#comment_2570080
type 'LineWidth' instead of 'MarkerSize'
Sign in to comment.
Sign in to answer this question.
Accepted Answer
Oleg Komarov on 30 Apr 2011
Edited: MathWorks Support Team on 8 Nov 2018
Open in MATLAB Online
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;
3 Comments Show 1 older commentHide 1 older comment
Show 1 older commentHide 1 older comment
Wo Mazdas on 23 Jul 2019
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/6537-how-do-i-change-the-marker-size-for-a-plot#comment_727279
Wonderful, just what I was looking for.
Sreekar Sai Ranganathan on 7 Sep 2021
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/6537-how-do-i-change-the-marker-size-for-a-plot#comment_1724264
Open in MATLAB Online
Is there a way to set this globally at startup for all plots?
For e.g., for line width of plots, I found that adding the following line in startup.m does it. Is there a similar property for the default marker size?
set(groot,'defaultLineLineWidth',1.3);
Sreekar Sai Ranganathan on 7 Sep 2021
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/6537-how-do-i-change-the-marker-size-for-a-plot#comment_1724279
Open in MATLAB Online
Nvm, figured it out. The following works:
set(groot,'defaultLineMarkerSize',4);
Also see this answer, if anyone needs something similar.
Sign in to comment.
More Answers (3)
Jan on 30 Apr 2011
Open in MATLAB Online
plot(x, x^2,'-k*');
hold('on');
plot(x, x^3,'-ko','MarkerSize', 12);
plot(x, x^4,'-k');
2 Comments Show NoneHide None
Show NoneHide None
Leo Simon on 22 May 2014
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/6537-how-do-i-change-the-marker-size-for-a-plot#comment_215185
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 on 29 Jan 2016
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/6537-how-do-i-change-the-marker-size-for-a-plot#comment_338847
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.
Sign in to comment.
Matt Fig on 30 Apr 2011
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:
LINECMENU
3 Comments Show 1 older commentHide 1 older comment
Show 1 older commentHide 1 older comment
Oleg Komarov on 30 Apr 2011
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/6537-how-do-i-change-the-marker-size-for-a-plot#comment_13512
+1
Michelle Hirsch on 29 Jan 2016
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/6537-how-do-i-change-the-marker-size-for-a-plot#comment_338848
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 on 1 Sep 2016
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/6537-how-do-i-change-the-marker-size-for-a-plot#comment_388511
yes
Sign in to comment.
Hari Desanur on 15 Nov 2016
Open in MATLAB Online
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 Comment Show -1 older commentsHide -1 older comments
Show -1 older commentsHide -1 older comments
P_L on 18 Apr 2019
Direct link to this comment
https://www.mathworks.com/matlabcentral/answers/6537-how-do-i-change-the-marker-size-for-a-plot#comment_695573
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
Sign in to comment.
Sign in to answer this question.
See Also
Categories
MATLABGraphicsFormatting and Annotation
Find more on Formatting and Annotation in Help Center and File Exchange
Tags
- plot
- marker size
- string symbol
- deep learning vs machine learning
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom(English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office