# Struggling to lay 2D points over a 3D scatter plot

조회 수: 4 (최근 30일)
Jane Halfhill 2023년 4월 4일
이동: the cyclist 2023년 4월 4일
Hello there!
I have a plot that shows tectonic plates subducting at a specific location (once tectonic plates go below the surface, they are called slabs. Referred to as slabs from here forward). I have my three slabs plotted using scatter3 and colored by depth as shown. What I want to add, though, are volcanoes at the surface of this plot.
First -- my code for the plot itself.
dat1 = load('kur_slab2_dep_02.24.18.xyz'); % Japan trench data
dat2 = load('ryu_slab2_dep_02.26.18.xyz'); % Ryukyu Nankai trench data
dat3 = load('izu_slab2_dep_02.24.18.xyz'); % Izu Bonin trench data
datf = [dat1; dat2; dat3]; % slabs put together
x1 = datf(:,1); % creating all xs
y1 = datf(:,2); % creating all ys
z1 = datf(:,3); % creating all zs
xv1 = linspace(min(x1), max(x1), 400); % creating linearly spaced points between min and max of all x
yv1 = linspace(min(y1), max(y1), 400); % creating linearly spaced points between min and max of all x
[X1,Y1] = meshgrid(xv1, yv1); % taking those linearly spaced points and making it into a grid
Z1 = griddata(x1,y1,z1,X1,Y1); % assigning a variable to the grid so it can be plotted
c = datf(:,3); % starting of colorbar info
figure(2)
scatter3(datf(:,1), datf(:,2), datf(:,3), 3, c); % plotting the information
title('The Boso Triple Junction subducting slabs');
xlabel(['Longitude (' char(176) ')']);
ylabel(['Latitude (' char(176) ')']);
zlabel('Slab Depth (km)');
col = colorbar;
set(get(col,'label'),'string','Depth in km');
grid on
This code creates this figure:
Now, I have volcanoes in the area in a file that looks something like:
Longitude Latitude Depth
125 45 0
137 43 0
140 39 0 etc.
I would love to have the volcanoes plotted as stars at the 'surface' (where depth of the slabs is equal to zero) of this plot, but I have been having trouble getting MATLAB to work with me (mostly because of my trouble with scatter3, I think, and figuring out how to alter the data format accordingly). Does anyone have any thoughts?
The slab data is too large to attach, but if anyone needs it or is curious, it's free data available at (https://www.sciencebase.gov/catalog/item/5aa1b00ee4b0b1c392e86467/). I use the Izu-bonin, Japan-Kuril-Kamchatka, and Ryukyu-Nankai depth xyz files (full name shown in code).
volcano data:
volclist.txt
Thank you for your time!!

댓글을 달려면 로그인하십시오.

### 채택된 답변

Ive J 2023년 4월 4일
이동: the cyclist 2023년 4월 4일
what about hold on?
hold on
voc = [125, 45, 0; 140, 39, 0];
scatter3(voc(:, 1), voc(:, 2), voc(:, 3), "*") % or plot3
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Jane Halfhill 2023년 4월 4일
이동: the cyclist 2023년 4월 4일
Hi there!
That totally worked! The code looks a little messy because I actually have about 200 volcanoes to plot, but I'm so happy that it plots and I'm really the only one who will ever see how it looks. I super appreciate your time and response to my question!

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by