How to plot XRD data as 3D plot?

10 visualizaciones (últimos 30 días)
Sam
Sam el 7 de Sept. de 2021
Comentada: Star Strider el 11 de En. de 2022
I have a series of XRD diffractograms from a single sample, at different depths. I want to plot the spectra as a 3D line plot, as seen as below:
(From https://link.springer.com/article/10.1016%2FS1672-6529%2806%2960003-6)
I use the following code to view my XRD data in Matlab:
data = importdata('example_data.dat') ; % load the data from text file
semilogy(data(:,1),data(:,2)) ; % plot the data
How do I go from here?
TIA

Respuesta aceptada

Star Strider
Star Strider el 7 de Sept. de 2021
Editada: Star Strider el 7 de Sept. de 2021
When I click on the link, I get a ‘DOI Not Found’ error. (EDIT — The new link is to an article behind a paywall, so I do not have access to it.)
That problem aside, if the data are in a matrix, it is likely possible just use surf to plot the matrix. The axis tick labels might need to be added manually in separate statements, however this is not difficult.
If you want to upload / attach the .XRD file, it would be necessary to put it into a .zip file first. Any information you have on its contents and format would be helpful, since I dioubt many here are familiar with that format (I am not, since .dat files can contain anything).
The complete matrix, with the values imported and plotted —
Uz = unzip('Plot3D[1].zip')
Uz = 1×103 cell array
{'Plot3D/569965_0-0.dat'} {'Plot3D/569965_0-1.dat'} {'Plot3D/569965_0-10.dat'} {'Plot3D/569965_0-100.dat'} {'Plot3D/569965_0-101.dat'} {'Plot3D/569965_0-102.dat'} {'Plot3D/569965_0-11.dat'} {'Plot3D/569965_0-12.dat'} {'Plot3D/569965_0-13.dat'} {'Plot3D/569965_0-14.dat'} {'Plot3D/569965_0-15.dat'} {'Plot3D/569965_0-16.dat'} {'Plot3D/569965_0-17.dat'} {'Plot3D/569965_0-18.dat'} {'Plot3D/569965_0-19.dat'} {'Plot3D/569965_0-2.dat'} {'Plot3D/569965_0-20.dat'} {'Plot3D/569965_0-21.dat'} {'Plot3D/569965_0-22.dat'} {'Plot3D/569965_0-23.dat'} {'Plot3D/569965_0-24.dat'} {'Plot3D/569965_0-25.dat'} {'Plot3D/569965_0-26.dat'} {'Plot3D/569965_0-27.dat'} {'Plot3D/569965_0-28.dat'} {'Plot3D/569965_0-29.dat'} {'Plot3D/569965_0-3.dat'} {'Plot3D/569965_0-30.dat'} {'Plot3D/569965_0-31.dat'} {'Plot3D/569965_0-32.dat'} {'Plot3D/569965_0-33.dat'} {'Plot3D/569965_0-34.dat'} {'Plot3D/569965_0-35.dat'} {'Plot3D/569965_0-36.dat'} {'Plot3D/569965_0-37.dat'} {'Plot3D/569965_0-38.dat'} {'Plot3D/569965_0-39.dat'} {'Plot3D/569965_0-4.dat'} {'Plot3D/569965_0-40.dat'} {'Plot3D/569965_0-41.dat'} {'Plot3D/569965_0-42.dat'} {'Plot3D/569965_0-43.dat'} {'Plot3D/569965_0-44.dat'} {'Plot3D/569965_0-45.dat'} {'Plot3D/569965_0-46.dat'} {'Plot3D/569965_0-47.dat'} {'Plot3D/569965_0-48.dat'} {'Plot3D/569965_0-49.dat'} {'Plot3D/569965_0-5.dat'} {'Plot3D/569965_0-50.dat'} {'Plot3D/569965_0-51.dat'} {'Plot3D/569965_0-52.dat'} {'Plot3D/569965_0-53.dat'} {'Plot3D/569965_0-54.dat'} {'Plot3D/569965_0-55.dat'} {'Plot3D/569965_0-56.dat'} {'Plot3D/569965_0-57.dat'} {'Plot3D/569965_0-58.dat'} {'Plot3D/569965_0-59.dat'} {'Plot3D/569965_0-6.dat'} {'Plot3D/569965_0-60.dat'} {'Plot3D/569965_0-61.dat'} {'Plot3D/569965_0-62.dat'} {'Plot3D/569965_0-63.dat'} {'Plot3D/569965_0-64.dat'} {'Plot3D/569965_0-65.dat'} {'Plot3D/569965_0-66.dat'} {'Plot3D/569965_0-67.dat'} {'Plot3D/569965_0-68.dat'} {'Plot3D/569965_0-69.dat'} {'Plot3D/569965_0-7.dat'} {'Plot3D/569965_0-70.dat'} {'Plot3D/569965_0-71.dat'} {'Plot3D/569965_0-72.dat'} {'Plot3D/569965_0-73.dat'} {'Plot3D/569965_0-74.dat'} {'Plot3D/569965_0-75.dat'} {'Plot3D/569965_0-76.dat'} {'Plot3D/569965_0-77.dat'} {'Plot3D/569965_0-78.dat'} {'Plot3D/569965_0-79.dat'} {'Plot3D/569965_0-8.dat'} {'Plot3D/569965_0-80.dat'} {'Plot3D/569965_0-81.dat'} {'Plot3D/569965_0-82.dat'} {'Plot3D/569965_0-83.dat'} {'Plot3D/569965_0-84.dat'} {'Plot3D/569965_0-85.dat'} {'Plot3D/569965_0-86.dat'} {'Plot3D/569965_0-87.dat'} {'Plot3D/569965_0-88.dat'} {'Plot3D/569965_0-89.dat'} {'Plot3D/569965_0-9.dat'} {'Plot3D/569965_0-90.dat'} {'Plot3D/569965_0-91.dat'} {'Plot3D/569965_0-92.dat'} {'Plot3D/569965_0-93.dat'} {'Plot3D/569965_0-94.dat'} {'Plot3D/569965_0-95.dat'} {'Plot3D/569965_0-96.dat'} {'Plot3D/569965_0-97.dat'} {'Plot3D/569965_0-98.dat'} {'Plot3D/569965_0-99.dat'}
x = readmatrix(Uz{1}, 'Range','A:A')
x = 1432×1
2.4604 2.4967 2.5330 2.5693 2.6056 2.6419 2.6782 2.7145 2.7508 2.7871
ymtx = NaN(numel(x),numel(Uz));
for k = 1:numel(Uz)
ymtx(:,k) = readmatrix(Uz{k}, 'Range','B:B');
end
ymtx
ymtx = 1432×103
1.0e+03 * 1.2665 1.2390 1.2957 1.3295 1.2866 1.2756 1.3268 1.2701 1.2829 1.2226 1.2783 1.2601 1.2372 1.3058 1.2701 1.2336 1.2683 1.3149 1.2665 1.2528 1.2866 1.2747 1.2875 1.2546 1.2372 1.2482 1.3030 1.2144 1.2601 1.2327 1.4501 1.4590 1.5009 1.4444 1.4293 1.4477 1.4837 1.4664 1.4704 1.4638 1.4245 1.4523 1.4647 1.4399 1.4495 1.4558 1.4585 1.4437 1.4214 1.4375 1.4426 1.4605 1.3969 1.4208 1.4349 1.4192 1.4393 1.3960 1.4216 1.4406 1.5363 1.5556 1.5773 1.5481 1.5332 1.5465 1.5618 1.5608 1.5676 1.5171 1.5129 1.5126 1.5346 1.5261 1.5019 1.5353 1.5379 1.5365 1.5386 1.5538 1.5134 1.5041 1.4984 1.5068 1.5035 1.5194 1.5506 1.5214 1.5161 1.5338 1.5478 1.5654 1.5978 1.5399 1.5437 1.5322 1.5942 1.6009 1.5492 1.5622 1.5534 1.5291 1.5382 1.5195 1.5467 1.5613 1.5274 1.5388 1.5266 1.5480 1.5368 1.5309 1.5295 1.5255 1.5020 1.5091 1.5594 1.5322 1.5028 1.5248 1.4311 1.4366 1.4876 1.4550 1.4216 1.4367 1.4829 1.4560 1.4595 1.4462 1.4493 1.4380 1.4247 1.4277 1.4316 1.4370 1.4438 1.4556 1.4439 1.4534 1.4486 1.4815 1.4257 1.4244 1.4333 1.4281 1.4484 1.4249 1.4361 1.4369 1.2854 1.2920 1.3296 1.2637 1.2814 1.2909 1.3275 1.3605 1.3120 1.2900 1.2933 1.2971 1.2904 1.2928 1.2848 1.2823 1.3208 1.2892 1.2776 1.2796 1.2881 1.2830 1.2718 1.2602 1.2691 1.2963 1.2687 1.2730 1.2636 1.2779 1.0883 1.0985 1.1391 1.1115 1.1109 1.0882 1.1312 1.1230 1.1519 1.1412 1.1091 1.1299 1.1354 1.1099 1.1019 1.0860 1.1173 1.1026 1.1176 1.1082 1.1124 1.1322 1.0924 1.1117 1.1133 1.1100 1.0867 1.1197 1.1160 1.1154 0.9009 0.8975 0.9614 0.9353 0.9231 0.9332 0.9357 0.9385 0.9338 0.9446 0.9514 0.9479 0.9511 0.9505 0.9511 0.8918 0.9264 0.9319 0.9417 0.9383 0.9411 0.9382 0.9312 0.9162 0.9311 0.9320 0.8924 0.9365 0.9382 0.9440 0.7658 0.7547 0.8386 0.8016 0.7964 0.8062 0.8311 0.8224 0.8386 0.8390 0.8350 0.8314 0.8377 0.8427 0.8188 0.7682 0.8285 0.8411 0.8219 0.8207 0.8176 0.8246 0.8032 0.8206 0.8204 0.8089 0.7647 0.8138 0.8006 0.7879 0.6761 0.6596 0.7479 0.7089 0.7084 0.7049 0.7126 0.7284 0.7231 0.7455 0.7445 0.7436 0.7518 0.7280 0.7464 0.6505 0.7565 0.7515 0.7362 0.7359 0.7348 0.7378 0.7407 0.7288 0.7355 0.7176 0.6595 0.7250 0.7209 0.7094
figure
surf(ymtx, 'EdgeColor','none')
grid on
xticklabels = string(x);
yt = yticks;
NrYticks = 9; % Choose Any Integer Divisor of '54'
set(gca, 'YTick',linspace(min(yt), max(yt), NrYticks), 'YTickLabel',linspace(0, -54, NrYticks))
xlabel('x')
ylabel('y')
zlabel('z')
view(60,30)
% shading('interp')
Experiment to get different results.
.
  10 comentarios
Sam
Sam el 11 de En. de 2022
Oh wow, thank you so much for such a quick response. As I'm not too familar with the language used at the start, I was struggling on this for quite a while.
Star Strider
Star Strider el 11 de En. de 2022
As always, my pleasure!
If you have further questions and have problems figuring out how the code works, don’t struggle longer than necessary. Just ask, and I’ll do my best to provide an appropriate solution (or explain the reason a solution isn’t possible).

Iniciar sesión para comentar.

Más respuestas (2)

KSSV
KSSV el 7 de Sept. de 2021
Read about surf. This is your function.

Sam
Sam el 7 de Sept. de 2021
Thank you for pointing this out, I have edited this!
My data is in three columns, the third column is redundant (errors), but the first and second column are my x and y, respectively.
The z values are in the file title, i.e. 569965_0-2.dat = 569965 (scan name); 0 (line number); 2 (spot/depth number, there are 102 spots for depth, this will be the z I assume)
I have attached one line here in my zip.

Etiquetas

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by