How to Change Marker Shape for Each Line in the Graph?
Show older comments
I need to change the marker shape for each line in the graph. Example (Square, tringle, plus...etc).
The excel sheet is attached.
Thanks!
clear all]
close all
clc
data=xlsread('xfoil-results.xlsx','ClCd');
color=[ [0, 0.4470, 0.7410];[0, 0, 1];[0.8500, 0.3250, 0.0980];[0, 0.5, 0];[0.9290, 0.6940, 0.1250];[1, 0, 0];[0.4940, 0.1840, 0.5560];[0, 0.75, 0.75];[0.4660, 0.6740, 0.1880];[0.75, 0, 0.75];[0.3010, 0.7450, 0.9330];[0.75, 0.75, 0];[0.6350, 0.0780, 0.1840];[0.25, 0.25, 0.25] ];
Re=[1e4,5e4,1e5,5e5,1e6];
Case_Name={'Re= 5x10^4','Re= 1x10^5','Re= 5x10^5','Re= 1x10^6'};
for i=1:2:size(data,1)
i
plot(data(i+1,:),data(i,:),'-d','MarkerEdge',color(i,:),'MarkerFace',color(i,:),'MarkerSize',8, 'LineWidth',2)
hold on
end
hold off
font=16;
font_matrk=8;
xlabel('Drag Coefficient (C_d)','FontSize', font)
ylabel('Lift Coefficient (C_l)','FontSize', font)
legend(Case_Name,'FontSize', font);
set(gca,'FontSize',font)
set(gcf,'color','w');
grid on;

Answers (2)
Walter Roberson
on 23 Jun 2020
Markers = '*+.<>^dhopsvx';
nMarkers = length(Markers);
for i=1:2:size(data,1)
i
midx = 1 + mod((i+1)/2 - 1, nMarkers); %cycle through them
plot(data(i+1,:), data(i,:), 'LineStyle', '-', 'Marker', Markers(midx), 'MarkerEdge', color(i,:), 'MarkerFace', color(i,:), 'MarkerSize', 8, 'LineWidth', 2);
hold on
end
This code does not do exactly what you asked for, in that it cycles through all the available markers, so markers would repeat every 13th row. MATLAB does not offer any way to create new markers, so to go beyond 13 of them, you would have to do something like use the File Exchange contribution that permits using arbitrary patches as markers. Use text() where you want the markers; you might be able to get up to a few hundred distinguishable markers that way.
4 Comments
Mokhtar
on 24 Jun 2020
Walter Roberson
on 24 Jun 2020
Markers = '0123456789#$%&+:?@ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuwxyz';
nMarkers = length(Markers);
for i=1:2:size(data,1)
midx = 1 + mod((i+1)/2 - 1, nMarkers); %cycle through them
plot(data(i+1,:), data(i,:), '-', 'LineWidth', 2);
hold on
text(data(i+1,:), data(i,:), Markers(midx), 'Color', color(i,:), 'FontSize', 8);
end
If you have more than 64 lines to draw then add more characters to Markers.
You might notice that I did not include all alphabetic characters in the list: I attempted to avoid ambiguity such as l vs 1 often being difficult to distinguish.
Walter Roberson
on 25 Jun 2020
The circles are coming from your line
plot(data(i+1,:),data(i,:),'-o','MarkerEdge',color(i,:),'MarkerFace',color(i,:),'MarkerSize',9, 'LineWidth',2)
Kamilu Sanusi
on 1 May 2023
@Walter Roberson, Please what could be the problem with this synthax
pzmap(T,'-d','MarkerSize',8)
8 Comments
pzmap() does not offer any direct way to customize the plot. You need to locate the appropriate objects and change their details.
sys = tf([1 2], [3 4 -5]);
pzmap(sys)
ax = gca;
PZZ = findobj(ax, 'Tag', 'PZ_Zero');
PZZ.Marker = 'd';
PZZ.MarkerSize = 8;
PZZ.Color = 'b';
PZP = findobj(ax, 'Tag', 'PZ_Pole');
PZP.Marker = 'v';
PZP.MarkerSize = 8;
PZP.Color = 'r';
Kamilu Sanusi
on 1 May 2023
Edited: Kamilu Sanusi
on 1 May 2023
@Walter Roberson, thank you so much. What is ax = gca; meant to do pls?
if i am plotting eigen values of more than one matrix, and I want to change the pole and zero of markers for each matrix on the same pz plot, please how do i make changes? I am more of concern with the thickness (boldness) of the marker than the size
if D == 15
pzmap(T,'r')
end
hold on
if D == 25
pzmap(T,'m')
end
Thank you
Walter Roberson
on 2 May 2023
The function gca returns the handle to the current axes graphics object. Assigning it to ax puts the handle into that variable.
The code could mostly be replaced with
sys = tf([1 2], [3 4 -5]);
pzmap(sys)
PZZ = findobj(gca, 'Tag', 'PZ_Zero');
PZZ.Marker = 'd';
PZZ.MarkerSize = 8;
PZZ.Color = 'b';
PZP = findobj(gca, 'Tag', 'PZ_Pole');
PZP.Marker = 'v';
PZP.MarkerSize = 8;
PZP.Color = 'r';
which executes the function gca twice instead of only executing it once and remembering the result. The difference between this an the previous version is that there are some cases in which the "current" axes can change between execution lines; if that happened then my original code would work fine but the version that calls gca() twice would have problems.
Walter Roberson
on 2 May 2023
ax = gca;
existing_Z = findobj(ax, 'PZ_Zero');
existing_P = findobj(ax, 'PZ_Pole');
if ismember(D, [15 25])
hold(ax, 'on')
pzmap(T);
new_Z = setdiff(existing_Z, findobj(ax, 'PZ_Zero'));
new_P = setdiff(existing_P, findobj(ax, 'PZ_Pole'));
new_ZP = [new_Z(:); new_P(:)];
set(new_ZP, 'MarkerSize', 8)
if D == 15
set(new_ZP, 'Color', 'r');
else
set(new_ZP, 'Color', 'm');
end
end
This code takes into account that there might be existing pzmap in the plot.
Note: pzmap() does not accept color or line specifications !!!
Kamilu Sanusi
on 2 May 2023
Edited: Walter Roberson
on 2 May 2023
@Walter Roberson, thank you for the response. I am sorry, it is returning error
Ta1 = 24; Ta2 = 27; Ta3= 20;
H11 = -0.0641; H12 = 0.0359;
H21 = 0.1176; H22 = -0.2057;
H31 = 0.2077; H32 = 0.1961;
for D = [0 4]
A = [0 0 1 0 -1;0 0 0 1 -1;(-H11/Ta1) (-H12/Ta1) (-D/Ta1) 0 0;...
(-H21/Ta2) (-H22/Ta2) 0 (-D/Ta2) 0;(-H31/Ta3) (-H32/Ta3) 0 0 (-D/Ta3)];
Eig = eig(A);
a = Eig(1,1);
b = Eig(2,1);
c = Eig(3,1);
d = Eig(4,1);
e = Eig(5,1);
s = tf('s');
T = (1)/((s-a)*(s-b)*(s-c)*(s-d)*(s-e));
P = pole(T);
if D == 0
pzplot(T)
end
hold on
if D == 4
pzmap(T);
end
% hold on
% if D == 7
% pzmap(T);
% end
grid on
ax = gca;
existing_Z = findobj(ax, 'PZ_Zero');
existing_P = findobj(ax, 'PZ_Pole');
if ismember(D, [0 4])
hold(ax, 'on')
pzmap(T);
new_Z = setdiff(existing_Z, findobj(ax, 'PZ_Zero'));
new_P = setdiff(existing_P, findobj(ax, 'PZ_Pole'));
new_ZP = [new_Z(:); new_P(:)];
set(new_ZP, 'MarkerSize', 8)
if D == 0
set(new_ZP, 'Color', 'r');
else
set(new_ZP, 'Color', 'm');
end
end
end
Ta1 = 24; Ta2 = 27; Ta3= 20;
H11 = -0.0641; H12 = 0.0359;
H21 = 0.1176; H22 = -0.2057;
H31 = 0.2077; H32 = 0.1961;
for D = [0 4]
A = [0 0 1 0 -1;0 0 0 1 -1;(-H11/Ta1) (-H12/Ta1) (-D/Ta1) 0 0;...
(-H21/Ta2) (-H22/Ta2) 0 (-D/Ta2) 0;(-H31/Ta3) (-H32/Ta3) 0 0 (-D/Ta3)];
Eig = eig(A);
a = Eig(1,1);
b = Eig(2,1);
c = Eig(3,1);
d = Eig(4,1);
e = Eig(5,1);
s = tf('s');
T = (1)/((s-a)*(s-b)*(s-c)*(s-d)*(s-e));
P = pole(T);
if D == 0
pzplot(T)
end
hold on
if D == 4
pzmap(T);
end
% hold on
% if D == 7
% pzmap(T);
% end
grid on
ax = gca;
existing_Z = findobj(ax, 'tag', 'PZ_Zero');
existing_P = findobj(ax, 'tag', 'PZ_Pole');
if ismember(D, [0 4])
hold(ax, 'on')
pzmap(T);
new_Z = setdiff(existing_Z, findobj(ax, 'tag', 'PZ_Zero'));
new_P = setdiff(existing_P, findobj(ax, 'tag', 'PZ_Pole'));
set(new_Z, 'Marker', 'd');
set(new_P, 'Marker', 'o');
new_ZP = [new_Z(:); new_P(:)];
set(new_ZP, 'MarkerSize', 8)
if D == 0
set(new_ZP, 'Color', 'r', 'MarkerFaceColor', 'r');
else
set(new_ZP, 'Color', 'm', 'MarkerFaceColor', 'm');
end
end
end
Walter Roberson
on 2 May 2023
I just noticed that in one case you pzplot() and in the other case you pzmap() . That is going to affect the code. In particular, you can record the output of pzplot() and it is a line handle directly, without needing to search for it, and also pzplot() does accept a line specification.
Kamilu Sanusi
on 2 May 2023
@Walter Roberson thank you so much for the assistance. I later changed to pzmap and it still generate error with few poles plotted.
I think pzplot could be better
h = pzplot(sys1,LineSpec1,...,sysN,LineSpecN) sets the line style, marker type, and color for the plot of each system. All systems must have the same number of inputs and outputs to use this syntax.
Ta1 = 24; Ta2 = 27; Ta3= 20;
H11 = -0.0641; H12 = 0.0359;
H21 = 0.1176; H22 = -0.2057;
H31 = 0.2077; H32 = 0.1961;
for D = [0 4]
A = [0 0 1 0 -1;0 0 0 1 -1;(-H11/Ta1) (-H12/Ta1) (-D/Ta1) 0 0;...
(-H21/Ta2) (-H22/Ta2) 0 (-D/Ta2) 0;(-H31/Ta3) (-H32/Ta3) 0 0 (-D/Ta3)];
Eig = eig(A);
a = Eig(1,1);
b = Eig(2,1);
c = Eig(3,1);
d = Eig(4,1);
e = Eig(5,1);
s = tf('s');
T = (1)/((s-a)*(s-b)*(s-c)*(s-d)*(s-e));
P = pole(T);
if D == 0
pzplot(T, 'Marker','d', 'MarkerSize', 8, 'LineWidth', 2);
end
hold on
if D == 4
pzplot(T, 'Marker','p', 'MarkerSize', 18, 'LineWidth', 2) ;
end
% hold on
% if D == 7
% pzmap(T);
% end
grid on
end
Categories
Find more on Discrete Data Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


