3 dataset plot in single dimension plane

2 views (last 30 days)
suraj karki
suraj karki on 13 Apr 2022
Edited: Riccardo Scorretti on 14 Apr 2022
Hello there,
I have facing a problem while plotting a data set.
I have three variables,
a,b and c.
I am trying to plot c with respect to a and b.
could you please figure out this situation.

Answers (2)

Riccardo Scorretti
Riccardo Scorretti on 13 Apr 2022
Hi Suraj, you can use mesh, surf, contour and many others functions (see https://fr.mathworks.com/help/matlab/visualize/representing-a-matrix-as-a-surface.html). For instance:
[x, y] = meshgrid(0:0.05:pi, 0:0.05:1);
c = exp(-2*y).*sin(-x);
figure
surf(x, y, c);
xlabel('x') ; ylabel('y') ; zlabel('c');
  5 Comments
suraj karki
suraj karki on 13 Apr 2022
Sure,
For an example
c = [0.001 0.002 0.003 0.00021 0.0025]
a = [65 45 35 55 33]
b = [80 114 85 90 95]
Now, I need to plot c with respect to a and b. which means a and b have a co-relation to produce data c.
I hope you will understand this situation.
Riccardo Scorretti
Riccardo Scorretti on 14 Apr 2022
Edited: Riccardo Scorretti on 14 Apr 2022
It is still unclear to me (sorry).
Method #1: you could plot a and b as a function of c, instead of c as a function of a and b:
c = [0.001 0.002 0.003 0.00021 0.0025];
a = [65 45 35 55 33];
b = [80 114 85 90 95];
[~, ind] = sort(c);
figure
yyaxis left
plot(c(ind), a(ind), 'o-') ; xlabel('c') ; ylabel('a');
yyaxis right
plot(c(ind), b(ind), 's-') ; ylabel('b');
The information is the same, but I guess it is not what you want.

Sign in to comment.


Riccardo Scorretti
Riccardo Scorretti on 14 Apr 2022
Edited: Riccardo Scorretti on 14 Apr 2022
Method #2: use circles of different size to represent the value of c. I hope at least it will inspire you.
c = [0.001 0.002 0.003 0.00021 0.0025];
a = [65 45 35 55 33];
b = [80 114 85 90 95];
% This parameter controls the average size of circles (just for aestetic purpose)
% I'm afraid it has to be adjusted manually depending on the number of
% points to plot and on the orders of magnitude of a and b
fact = 0.1;
figure
sz = fact*max(abs([a(:) ; b(:)])) / max(abs(c(:))); % = characteristic size to draw circles
sz_b = 0.01*max(abs(b));
t_ = linspace(0, 2*pi, 256);
assert(numel(a) == numel(b) && numel(a) == numel(c), 'a, b, and c must have the same number of elements');
for n = 1 : numel(c)
patch(a(n)+sz*c(n)*cos(t_), b(n)+sz*c(n)*sin(t_), 'r', ...
'EdgeColor', 'k', 'FaceAlpha', 0.4);
hold on
text(a(n), b(n)+sz*c(n)+sz_b, num2str(c(n)));
end
axis square ; box on ; grid on
xlabel('a') ; ylabel('b');

Community Treasure Hunt

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

Start Hunting!