Different X axis location. Unsure Why.
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am performing two very similar plots but the placement of the xlabel is different and I cant determine why or how to rectify it. I would prefer to force the xlabel to be as in my first example:
%clearing crap
clear all
clf
%selecting amazing font
set(0, "DefaultAxesFontName", "Courier New");
set(0, "DefaultTextFontName", "Courier New");
%importing required data
%importing data
Raman = readtable("Pfile.csv");
%converting data
shift = table2array(Raman(:,1));
MW0 = table2array(Raman(:,2));
AlMW25 = table2array(Raman(:,3));
AlMW5 = table2array(Raman(:,4));
%plotting MW0
plot(shift, MW0)
hold on %plotting on same graph
plot(shift, AlMW25)
plot(shift, AlMW5)
hold off %end of plotting
%beautifying curve
ax = gca;
ax.XAxisLocation = "origin";
ax.YAxisLocation = "origin";
box off;
%labelling graph
xlabel("Raman Shift [cm^{-1}]");
ylabel("Intensity [Arb. Units.]");
title("Raman Spectra")
legend("MW 0","AlMW 2.5","AlMW 5","Location","north west")
This returns the following graph:

In example two i get the following:
%clearing crap
clear all
clf
%selecting amazing font
set(0, "DefaultAxesFontName", "Courier New");
set(0, "DefaultTextFontName", "Courier New");
%importing required data
%importing data
Raman = readtable("Ufile5.csv");
%converting data
shift0 = table2array(Raman(:,1));
NBS0 = table2array(Raman(:,2));
shift1 = table2array(Raman(:,3));
NBS1 = table2array(Raman(:,4));
shift2 = table2array(Raman(:,5));
NBS2 = table2array(Raman(:,6));
shift3 = table2array(Raman(:,7));
NBS3 = table2array(Raman(:,8));
shift4 = table2array(Raman(:,9));
NBS4 = table2array(Raman(:,10));
%plotting NBS0
plot(shift0, NBS0)
hold on %plotting on same graph
plot(shift1, NBS1)
plot(shift2, NBS2)
plot(shift3, NBS3)
plot(shift4, NBS4)
hold off %end of plotting
%beautifying curve
ax = gca;
ax.XAxisLocation = "origin";
ax.YAxisLocation = "origin";
box off;
xlabel("Raman Shift [cm^{-1}]"); % Store handle
ylabel("Intensity [Arb. Units.]");
title("Raman Spectra for NBS Glasses");
legend("NBS 0", "NBS 1", "NBS 2", "NBS 3", "NBS 4", "Location", "northwest");
and i get the followign less optimal xlabel position:

0 Kommentare
Antworten (1)
dpb
am 3 Feb. 2025
Bearbeitet: dpb
am 4 Feb. 2025
set(0, "DefaultAxesFontName", "Courier New");
set(0, "DefaultTextFontName", "Courier New");
Raman = readtable("Ufile5.csv");
N=5; % number of shift pairs
Raman.Properties.VariableNames(1:2:2*N)=compose('shift%d',[0:N-1]); % if not named, create desired names
Raman.Properties.VariableNames(2:2:2*N)=compose('NBS%d',[0:N-1]);
for i=1:2:2*N % plotting NBSn in turn...
plot(Raman.(Raman.Properties.VariableNames{i}),Raman.(Raman.Properties.VariableNames{i+1}))
if i==1, hold on, end %plotting on same graph
end
box off;
xlabel("Raman Shift [cm^{-1}]"); % Store handle
ylabel("Intensity [Arb. Units.]");
title("Raman Spectra for NBS Glasses");
legend(Raman.Properties.VariableNames(2:2:2*N), "Location", "northwest");
Remove the XAxis.Location, YAxis.Location change from the default and all will be well.
There's no need to create copies of existing data; use the table.
I created the equivalent variable names in the table for you if they aren't already what is wanted when read in...that's optional but convenient.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Labels and Annotations finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!