0

I want to clarify the relationship between the function and its three arguments through one figure, such as y=f(a,b,c), where y varies with three arguments a,b,c.

But it seems impossible. Is there any good solution to this problem? Or other reasonable method to visualize the relationship well?

I wonder if I can draw a 3-D figure with three axises a,b,c, and use the color depth to represent the function value. Can this be realized?

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
Land
  • 3
  • 4
  • Are you asking how to plot a function of 3 variables? Like [this](https://stackoverflow.com/q/1809881/52738)? – gnovice Mar 28 '19 at 16:15
  • Welcome to StackOverflow. A minimal [example](https://stackoverflow.com/help/mcve), your example code, and a description of what you're wanting specifically will get you a lot more help. See [how to ask](https://stackoverflow.com/help/mcve) – SecretAgentMan Mar 28 '19 at 16:16
  • Have you looked at [these approaches](https://stackoverflow.com/q/16868074/8239061) complete with code? For example, using [scatter3](https://www.mathworks.com/help/matlab/ref/scatter3.html) with different marker types or colors would allow you to visualize 4–5 variables depending on your specific application. – SecretAgentMan Mar 28 '19 at 16:16
  • @SecretAgentMan Thanks. Indeed, these methods may not work, since what I need can be viewed as a 4-D figure. – Land Mar 28 '19 at 16:23
  • @gnovice. Thank you. Yes, it can be 4-D figure. It seems helpful. Thanks again! – Land Mar 28 '19 at 16:25
  • @gnovice, should I move my answer from [here](https://stackoverflow.com/a/55402696/8239061) to the [dupe there](https://stackoverflow.com/q/1809881/8239061) then delete the one below? Or should I just leave it alone since it was upvoted and accepted? – SecretAgentMan Mar 28 '19 at 21:46
  • @SecretAgentMan: I guess just leave it. – gnovice Apr 01 '19 at 17:11
  • @gnovice, thanks, just wanted to do the right thing after you found that dupe. – SecretAgentMan Apr 01 '19 at 17:25

1 Answers1

1

This is an example of using scatter3 to plot multiple variables. Changing marker type adds more functionality. Notice we still haven't made use of the S (marker size) argument in scatter3(X,Y,Z,S,C).

However, this may not be a good visualization for some applications. Some other resources listed below.

3D Scatterplot example with different markers and colors for higher dimensional visualization.

% MATLAB R2017a
n = 50;
X = 10*rand(n,1);
Y = 15*rand(n,1);
Z = 20*rand(n,1);
V = 100*rand(n,1); 

idxA = X + Y > 15;
idxB = ~idxA;

colormap(cmap), hold on, box on
p(1) = scatter3(X(idxA),Y(idxA),Z(idxA),[],V(idxA),'filled');
p(2) = scatter3(X(idxB),Y(idxB),Z(idxB),[],V(idxB),'filled');
p(2).Marker = 'd';
cb = colorbar;
view([-5 -2 -2])

p(1).MarkerEdgeColor = 'k';
p(2).MarkerEdgeColor = 'k';
xlabel('X')
ylabel('Y')
zlabel('Z')
cb.Label.String = 'V';  

Other resources:
This post with 3D and 4D solutions. Future visitors may find this post valuable as well due to its many examples complete with code.

MATLAB references:
MATLAB Plot Types
MATLAB Plot Gallery

SecretAgentMan
  • 2,856
  • 7
  • 21
  • 41
  • Thank you! Can we use line to connect these scatters? – Land Mar 28 '19 at 16:40
  • Since it is in 3D, you mean something like [`surface`](https://www.mathworks.com/help/matlab/ref/surface.html) or [`surf`](https://www.mathworks.com/help/matlab/ref/surf.html)? – SecretAgentMan Mar 28 '19 at 16:48
  • Yes. Since they are discrete, it will be a little difficult to get the varing trendency. – Land Mar 28 '19 at 16:53
  • Have you looked at ['ribbon'](https://www.mathworks.com/help/matlab/ref/ribbon.html) or ['plot3'](https://www.mathworks.com/help/matlab/ref/plot3.html) ("LineSpec" property set to `'-'`)? – SecretAgentMan Mar 28 '19 at 17:06
  • I don't see why you couldn't plot the point markers over top one of the other plots. So, yes, I think that's possible if that's the question. – SecretAgentMan Mar 28 '19 at 17:09