필터 지우기
필터 지우기

2 axis plotting with different markers

조회 수: 6 (최근 30일)
uki71319
uki71319 2022년 12월 17일
편집: uki71319 2023년 3월 27일
Dear all, i'm trying to plot 2 axis lines with the corresponding 5 different markers. But the code (commented one) always got errors.
Could anyone tell me how can i solve this issue???
Any help is greatly appreciated.
%plotting
% I want to plot two axis with different markers for Yleft(hollow marker)and Xleft (filled marker),
% different markers are connected with lines
rate=[5,10,15,20,25]
Yleft=[1.99,2.78,2.67,2.54,2.45]
d=plot(f,Yleft,'.-')
%plot(f(1),Yleft(1),'o',rate(2),Yleft(2),'*',rate(3),Yleft(3)','^',rate(4),Yleft(4),'square',rate(5),Yleft(5),'dimaond')
% d(1).Marker="o";
% d(2).Marker="*"
% d(3).Marker="^"
% d(4).Marker="square"
% d(5).Marker='diamond'
yyaxis left
title('Yleft and Xleft vs. z ')
xlabel('flow rate [m^3/s]')
ylabel('YLeft [W/m/K]')
yyaxis right
Xleft=[1070,695,636,680,758]
f=plot(rate,Xleft,'*-')
% f(1).Marker="o";
% f(2).Marker="*"
% f(3).Marker="^"
% f(4).Marker="square"
% f(5).Marker='diamond'
ylabel('XLeft [W/m^2/K]')

채택된 답변

Askic V
Askic V 2022년 12월 17일
편집: Askic V 2022년 12월 17일
I would do somthing like this:
%plotting
% I want to plot two axis with different markers for lambda_r (hollow marker)and alpha_w (filled marker),
% different markers are connected with lines
f=[5,10,15,20,25];
lam=[1.99,2.78,2.67,2.54,2.45];
d=plot(f,lam,'.-');
hold on
markers = {'o','*','^','square', 'diamond'};
for i = 1:numel(f)
plot(f(i),lam(i),markers{i});
end
yyaxis left
title('lambda\_r and alpha\_w vs. z ')
xlabel('flow rate [m^3/s]')
ylabel('lambda\_r [W/m/K]')
  댓글 수: 2
Askic V
Askic V 2022년 12월 17일
편집: Askic V 2022년 12월 17일
Even though VBBV already posted, I'll answer to your questions regarding the color in the following way:
%plotting
% I want to plot two axis with different markers for lambda_r (hollow marker)and alpha_w (filled marker),
% different markers are connected with lines
f=[5,10,15,20,25];
lam=[1.99,2.78,2.67,2.54,2.45];
plot(f,lam,'b.--' )
hold on
markers = {'o','*','^','square', 'diamond','b'};
for i = 1:numel(f)
plot(f(i),lam(i),['b' markers{i}]);
end
yyaxis left
title('lambda\_r and alpha\_w vs. z ')
xlabel('flow rate [m^3/s]', 'Color', 'k')
ylabel('lambda\_r [W/m/K]', 'Color', 'b')
ax = gca;
set(ax, 'YColor', 'r')
yyaxis right
k_w=[1070,695,636,680,758]
k_w = 1×5
1070 695 636 680 758
plot(f,k_w,'r*--')
markers = {'o','*','^','square', 'diamond'};
for i = 1:numel(f)
d = plot(f(i),k_w(i),['r' markers{i}]);
end
ylabel('alpha\_w [W/m^2/K]', 'Color', 'r')
ax = gca;
set(ax, 'YColor', 'b')
uki71319
uki71319 2022년 12월 18일
Dear @Askic V, thank you very much! This works!!!
But i have one last question: Do you know to legend out only the "o" markers in both red and blue lines??
i try to legend both of them. However, the first legend always comes out the "-" straight line marker, instead of the round "o" marker legend...

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

추가 답변 (1개)

Askic V
Askic V 2022년 12월 18일
If you want to have legend only on points 'o' in both red and blue lines, I would do this:
%plotting
% I want to plot two axis with different markers for lambda_r (hollow marker)and alpha_w (filled marker),
% different markers are connected with lines
f = [5,10,15,20,25];
lam = [1.99,2.78,2.67,2.54,2.45];
plot(f,lam,'b.-' );
hold on
markers = {'o','*','^','square', 'diamond','b'};
for i = 1:numel(f)
d(i)= plot(f(i),lam(i),['b' markers{i}]);
end
yyaxis left
title('lambda\_r and alpha\_w vs. z ')
xlabel('flow rate [m^3/s]', 'Color', 'k')
ylabel('lambda\_r [W/m/K]', 'Color', 'b')
ax = gca;
set(ax, 'YColor', 'r')
yyaxis right
k_w=[1070,695,636,680,758];
plot(f,k_w,'r*--')
markers = {'o','*','^','square', 'diamond'};
for i = 1:numel(f)
h(i) = plot(f(i),k_w(i),['r' markers{i}]);
end
ylabel('alpha\_w [W/m^2/K]', 'Color', 'r')
legend([d(1) h(1)],'Point o blue','Point o red');
ax = gca;
set(ax, 'YColor', 'b')
  댓글 수: 1
uki71319
uki71319 2022년 12월 18일
Wow, thank you very much sir!!!!! I was struggling with this for the whole day yesterday.
Thank you again!

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

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by