14 views (last 30 days)
Show older comments
Joel on 6 Oct 2016
Commented: Joel on 6 Oct 2016
Accepted Answer: Giovanni Mottola
Open in MATLAB Online
I want to show my data in a scatter3 plot.
However, the way the data is shown, it is not very clear where exactly on the 3 axis the data points are.
An example,
figure;
x = 0.9914;
y = 0.0390;
z = 20
scatter3(x,y,z,'filled')
view(-30,10)
What I would like to do is to draw a dashed line straight downwards from the point, so that it is clearer where the point is on the XY plane. Also, I would like to draw a dashed line from the point to the Z axis, so that it is clear where the point is on the Z axis plane.
If this turns out to be too messy I will look at a way to write the XYZ values for each point just above each point.
0 Comments Show -2 older commentsHide -2 older comments
Show -2 older commentsHide -2 older comments
Sign in to comment.
Sign in to answer this question.
Accepted Answer
Giovanni Mottola on 6 Oct 2016
⋮
Open in MATLAB Online
Here I assumed x, y, z are vectors of length "len".
To draw a line joining each scatter point to the horizontal plane use:
hold on
for i=1:len
plot3([x(i), x(i)], [y(i), y(i)], [0, z(i)], 'b--')
end
To draw a line joining each scatter point to the vertical axis use:
for i=1:len
plot3([0, x(i)], [0, y(i)], [z(i), z(i)], 'r--')
end
Final result for len=5 (random points):
5 Comments Show 3 older commentsHide 3 older comments
Show 3 older commentsHide 3 older comments
Joel on 6 Oct 2016
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/306041-scatter3-insert-dashed-line-downwards-and-sideways#comment_396423
Open in MATLAB Online
Thanks!
The dashed line downwards works just like I want it to!
However, something is off with the dashed line for the Z axis. It is not dashed in a 90 degree angle, i.e. it shows the wrong z axis value. I have not yet figured out why this is. I tried setting the Z value to the maximum to see, and the dashed line is not right. COuld it be because in ym example the 3 axis are not of the same length (same min/max)?
This is a minimum working example of my code,
figure;
x = 0.9914;
y = 0.0390;
z = 2
scatter3(x,y,z,'filled')
ylim([-2, 2])
xlim([-2 2])
zlim([0 2])
hold on
plot3([x, x], [y, y], [0, z], 'b--')
plot3([0, x], [0, y], [z, z], 'r--')
view(-30,10)
Giovanni Mottola on 6 Oct 2016
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/306041-scatter3-insert-dashed-line-downwards-and-sideways#comment_396457
I tried running your code and I'm not sure what the problem is. My results are below. Are you sure it's not a matter of perspective? Could you try to set the same limits for x, y and z axes (with xlim etc.)?
Joel on 6 Oct 2016
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/306041-scatter3-insert-dashed-line-downwards-and-sideways#comment_396471
Very strange that your figure looks perfect. Hm. As you can see in the image, it is clear that the red dashed line does not go to the value 2 on the Z axis.
I really do not have any good guess as to why this could be at the moment.
Thank you for your help thus far. I appreciate it!
Giovanni Mottola on 6 Oct 2016
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/306041-scatter3-insert-dashed-line-downwards-and-sideways#comment_396486
Open in MATLAB Online
Try:
view([0, 0])
ylim([0 2.2])
xlim([0 2.2])
zlim([0 2.2])
And
view([90, 0])
ylim([0 2.2])
xlim([0 2.2])
zlim([0 2.2])
Joel on 6 Oct 2016
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/306041-scatter3-insert-dashed-line-downwards-and-sideways#comment_396531
Thanks Giovanni!
You are/were indeed right that it is an issue of perspective.
Still if I would like to show this plot to someone it is very misleading. By looking at the figure I posted one does not think the Z value is 2.
I tried some other perspectives and I noticed that when the first variable of view is negative I get plot where it seems like Z is not 2. If I change it to positive, then it looks as I expect it to!
Thank you very much for your help!
Sign in to comment.
More Answers (0)
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
- scatter3 plot
Products
- MATLAB
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.
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)
- 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
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)
Contact your local office