2 axis plotting with different markers
Show older comments
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]')
Accepted Answer
More Answers (1)
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')
Categories
Find more on Data Distribution 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!

