Plotting 4-D graph, 3-D with 4th dimension colored (2024)

67 views (last 30 days)

Show older comments

Bus141 on 5 May 2015

  • Link

    Direct link to this question

    https://matlabcentral.mathworks.com/matlabcentral/answers/215166-plotting-4-d-graph-3-d-with-4th-dimension-colored

  • Link

    Direct link to this question

    https://matlabcentral.mathworks.com/matlabcentral/answers/215166-plotting-4-d-graph-3-d-with-4th-dimension-colored

Commented: Walter Roberson on 23 Jan 2020

Accepted Answer: Cindy Solomon

Open in MATLAB Online

I am trying to plot a 3-D figure from 4 variables, the first 3 are semi-repetitive and the 4th one is the one from which I would like colors. In my actual set the 4th is not repetitive in any order but repetitive more randomly. Below is a generic code of my data looks like.

x=1:2:20; x=x'; x=[x;x;x;x;x;x];

y=ones(10,1); y=[y;y+1;y+2];y=[y;y];

z=ones(30,1)*2; z=[z;z+1];

c=1:4; c=c'; c=repmat(c,15,1);

scatter3(x,y,z,c,'filled')

As you can see from the figure it is hard to tell which dot is for which value of c. I am not set on using this graph if better ideas are out there. Any help is appreciated. Thanks!

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

Accepted Answer

Cindy Solomon on 7 May 2015

  • Link

    Direct link to this answer

    https://matlabcentral.mathworks.com/matlabcentral/answers/215166-plotting-4-d-graph-3-d-with-4th-dimension-colored#answer_178278

Open in MATLAB Online

Hi Bus,

What sort of data are you trying to visualize? Without a specific idea, a few general recommendations for you:

  • For better visualization of functions of 4 variables, I recommend taking a look at sliceomatic
  • For visualizing the fourth dimension specifically with color, you can change the size of the markers and/or colors of each point with scatter3. For example, if I replaced your last line with:

markerSize = 100;

scatter3(x,y,z,markerSize,c,'filled')

colorbar

then the plot will now have data points whose color is the linear mapping of the values in C to the colors in the current colormap- the way you had it before was altering the size instead of color. If you would prefer to specify a RBG color value instead, you could also give it a 3 column matrix with the number of rows in C equal to the length of X, Y, and Z. This way, each row could then specify an RGB color value for each marker. This is especially handy if you want to change each marker separately (by size and/or color). You could also change the RGB value to be proportional to the value of c (ex: c/max(c)) as well.

Hope this helps!

1 Comment

Show -1 older commentsHide -1 older comments

Bus141 on 7 May 2015

Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/215166-plotting-4-d-graph-3-d-with-4th-dimension-colored#comment_283690

  • Link

    Direct link to this comment

    https://matlabcentral.mathworks.com/matlabcentral/answers/215166-plotting-4-d-graph-3-d-with-4th-dimension-colored#comment_283690

Thanks! Yeah it appears I was trying to place the values in the wrong place.

I am having an issue getting the legend to make sense. The fourth dimension I am using has discrete values, so while the colorbar helps if you know the graph really well, I think it would be easier to interpret if the values corresponded to a legend or key. Any thoughts?

Sign in to comment.

More Answers (1)

Cindy Solomon on 7 May 2015

  • Link

    Direct link to this answer

    https://matlabcentral.mathworks.com/matlabcentral/answers/215166-plotting-4-d-graph-3-d-with-4th-dimension-colored#answer_178290

  • Link

    Direct link to this answer

    https://matlabcentral.mathworks.com/matlabcentral/answers/215166-plotting-4-d-graph-3-d-with-4th-dimension-colored#answer_178290

Open in MATLAB Online

Hi Bus,

If your fourth dimension is only a small number of discrete values, I agree a legend would make more sense (Although you can make a colorbar with only 10 entries, a legend is probably a bit easier to read.)

You might have had some trouble creating different legend entries if you only had one plot object- it would be easiest to plot each c-value independently like you would when overlaying plots on top of each other with "hold on." For example, you could do something like:

cVals = unique(c); % Find all unique values of c

for i = 1:numel(cVals) % For every one of those unique values

indices = find(c == cVals(i)); % Find the corresponding indices

scatter3(x(indices),y(indices),z(indices),100,'filled') % Plot

hold on

end

legend('C = 1', 'C = 2','C = 3','C = 4');

to get the behavior that I think you are describing?

4 Comments

Show 2 older commentsHide 2 older comments

Bus141 on 7 May 2015

Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/215166-plotting-4-d-graph-3-d-with-4th-dimension-colored#comment_283712

  • Link

    Direct link to this comment

    https://matlabcentral.mathworks.com/matlabcentral/answers/215166-plotting-4-d-graph-3-d-with-4th-dimension-colored#comment_283712

Works perfectly. Thanks a lot, appreciate it!

Cindy Solomon on 8 May 2015

Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/215166-plotting-4-d-graph-3-d-with-4th-dimension-colored#comment_283853

  • Link

    Direct link to this comment

    https://matlabcentral.mathworks.com/matlabcentral/answers/215166-plotting-4-d-graph-3-d-with-4th-dimension-colored#comment_283853

No problem- happy to help! =)

Abhishek Chopra on 23 Jan 2020

Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/215166-plotting-4-d-graph-3-d-with-4th-dimension-colored#comment_789001

  • Link

    Direct link to this comment

    https://matlabcentral.mathworks.com/matlabcentral/answers/215166-plotting-4-d-graph-3-d-with-4th-dimension-colored#comment_789001

Hi Cindy,

My problem is almost the same, except I have 1000 unique values. Is there a way that I could assign 1000 unique colors or a way to visualzie them better? Thank you!

Walter Roberson on 23 Jan 2020

Direct link to this comment

https://matlabcentral.mathworks.com/matlabcentral/answers/215166-plotting-4-d-graph-3-d-with-4th-dimension-colored#comment_789013

  • Link

    Direct link to this comment

    https://matlabcentral.mathworks.com/matlabcentral/answers/215166-plotting-4-d-graph-3-d-with-4th-dimension-colored#comment_789013

Humans have a hard time distinguishing that many colors. Realistically you should only use perhaps 25 colors. You can combine them with different line styles and marker shapes.

Sign in to comment.

Sign in to answer this question.

See Also

Categories

MATLABGraphics2-D and 3-D Plots

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

  • 4-d plot
  • scatter3
  • 3-d color

Community Treasure Hunt

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

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


Plotting 4-D graph, 3-D with 4th dimension colored (9)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

Contact your local office

Plotting 4-D graph, 3-D with 4th dimension colored (2024)

FAQs

Can humans visualize 4D? ›

While we can't directly visualize four-dimensional space, math provides tools for representing and comprehending it, expanding our geometric understanding.

What is the 4th dimension for dummies? ›

The fourth dimension is defined as a space containing coordinates beyond length, width, and depth. Therefore, it is an extension of the third dimension and provides more range of motion for particles.

What is a 4D shape? ›

Some of the most studied four-dimensional shapes are hypercubes, hyperspheres, and Klein Bottles. The 4th Dimension. We use dimensions to describe the world around us. Each new dimension expands from the previous ones in a new spatial direction. The 4th dimension of space is an extension of the 3rd dimension.

Why can't we see in 4 dimensions? ›

The fact that we are unable to think in more than three dimensions suggests that visualising four or more dimensions simply provided no survival or reproductive value to our ancestors – this isn't really surprising since our daily lives are played out in a three-dimensional physical space.

How does the 5th dimension look like? ›

This is completely invisible to the human eye, and smaller than subatomic particles like electrons and quarks. The dimension is also thought to be closed in on itself, meaning there's no direct, visible “opening” to it. The 5th dimension can't be observed, but its influence might be visible.

Is 4D possible in real life? ›

The world we see around us seems to have three space dimensions. This is physics as we know it. WE don't know how to make 4D objects, which is why the tesseracts you have seen are only 2D or 3D projections. That doesn't prove that true 4D objects don't exist, somewhere.

What would a 4D being look like? ›

Have you ever considered how a four-dimensional being would appear to you if it suddenly came into your room? I think they would resemble flesh-colored balloons constantly changing in size. We would see disconnected blobs of flesh, some attached to claws, teeth, lips, eyes, or hair.

Do we live in 3D or 4D? ›

In everyday life, we inhabit a space of three dimensions – a vast 'cupboard' with height, width and depth, well known for centuries. Less obviously, we can consider time as an additional, fourth dimension, as Einstein famously revealed.

Is there a 5D shape? ›

In five-dimensional geometry, a 5-cube is a name for a five-dimensional hypercube with 32 vertices, 80 edges, 80 square faces, 40 cubic cells, and 10 tesseract 4-faces.

What dimensional world do we live in? ›

We live in a world of three dimensions.

We move through space , either left or right, forward or backward, up or down. Everything around us, from the houses we live in to the objects we use in everyday life, has three dimensions: height, length, and width.

Is there a 0D shape? ›

There exists only one connected 0D shape: the point. This is the member of all shape families with a zero-dimensional member; this makes it the zero-dimensional hypercube, hyperball, cross polytope, as well as the only zero-dimensional rotatope and toratope.

What is the fourth dimension of spirituality? ›

The idea of a soul moving into the fourth dimension and being eternal allays the fear of death to many people. Higher dimensions can be used to provide a future beyond death. Religion may not be necessary to as many people in the future as an explanation of death.

Are black holes 4D? ›

A black hole is actually a four-dimensional object. A black hole extends across all four physical dimensions of the universe. The four dimensions that form the background framework of the universe consist of three spatial dimensions and one time dimension.

Are we living in the 4th dimension? ›

We move through three dimensions. Or do we? String theorists believe our world encompasses more than three dimensions. Without experiential evidence, the mathematical theory of space and time as a fourth dimension has remained just that since the days of Albert Einstein: a theory.

Can humans think in the 4th dimension? ›

You can't. There are only three spatial dimensions. And beyond that, you can't even think of a fourth spatial dimension, because our brains evolved in a three-dimensional world (there are some people who claim that they can imagine a fourth dimension, but I suspect that they're either lying or just fooling themselves).

Is human vision 4D? ›

We are 3D creatures, living in a 3D world but our eyes can show us only two dimensions. The depth that we all think we can see is merely a trick that our brains have learned; a byproduct of evolution putting our eyes on the front of our faces.

Can the human eye see the 4th dimension? ›

“But just as the hose has a curled-up dimension, maybe space itself has curled up dimensions all around us, just curled up to such a fantastically small size we can't see them with our eyes,” he says. “We can't see them even with today's most powerful microscopes.”

Is it possible to think in 4D? ›

Moving into 4D thinking, we begin to visualise the metaphysical nature of time and space itself. In doing so, we connect our consciousness to our ultimate reality. Rather than trying to manifest the reality we think we want, we connect to our higher self. We can receive new inspirations, and new ideas.

Is it possible to have a 4D graph? ›

It is, of course, impossible to fully render four dimensional functions in this three dimensional world. However, we can get some sort of visual feel for a 4D function by graphing some of its level sets.

References

Top Articles
Latest Posts
Article information

Author: Catherine Tremblay

Last Updated:

Views: 6424

Rating: 4.7 / 5 (47 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Catherine Tremblay

Birthday: 1999-09-23

Address: Suite 461 73643 Sherril Loaf, Dickinsonland, AZ 47941-2379

Phone: +2678139151039

Job: International Administration Supervisor

Hobby: Dowsing, Snowboarding, Rowing, Beekeeping, Calligraphy, Shooting, Air sports

Introduction: My name is Catherine Tremblay, I am a precious, perfect, tasty, enthusiastic, inexpensive, vast, kind person who loves writing and wants to share my knowledge and understanding with you.