2 axis plotting with different markers
5 次查看(过去 30 天)
显示 更早的评论
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]')
0 个评论
采纳的回答
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
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]
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')
更多回答(1 个)
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')
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Specifying Target for Graphics Output 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!