How to Change Marker Shape for Each Line in the Graph?

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;

답변 (2개)

Walter Roberson
Walter Roberson 2020년 6월 23일
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

Hi Mr. Walter,
Thanks for the quick response. Unfortionately I don't know how to "Use text() where you want the markers" . If you could explain a little bit more I would highly appriciate it.
Thanks!
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.
Mokhtar
Mokhtar 2020년 6월 25일
편집: Mokhtar 2020년 6월 25일
Thank you for making it clear and easier to understand . However, sadly, it didn't work. I can see that the legends have changed, but the points in the graph are still circles. still circles.
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] ];
Markers = '*+.<>^dhopsvx';
nMarkers = length(Markers);
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
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)
plot(data(i+1,:),data(i,:),'-o','MarkerEdge',color(i,:),'MarkerFace',color(i,:),'MarkerSize',9, '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;
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
Kamilu Sanusi 2023년 5월 1일
@Walter Roberson, Please what could be the problem with this synthax
pzmap(T,'-d','MarkerSize',8)

댓글 수: 8

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
Kamilu Sanusi 2023년 5월 1일
편집: Kamilu Sanusi 2023년 5월 1일
@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
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.
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 !!!
@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
Error using matlab.graphics.axis.Axes/findobj
Incomplete parameter-value pair.
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
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.
@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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

2020년 6월 23일

댓글:

2023년 5월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by