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

64 次查看(过去 30 天)
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 个评论
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;
Walter Roberson
Walter Roberson 2020-6-25
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 个评论
Walter Roberson
Walter Roberson 2023-5-2
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
Kamilu Sanusi 2023-5-2
@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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by