Display 2D Data in a 3D plot
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
For a task i need to make 3D-Plot of following Data and compare them in one plot.
Emissions transport (28x1)
Emissions Flug-Schiffsverkehr (28x1)
Years (28x1)
so in one plot ( x = years, y = Data1, z=x) %% I made z=x because i dont know what other data i should use.
other plot ( x = years, y = Data2, z=x)
Has anyone an idea so it makes sense to do this in 3d.
here is my code as far
excel = readmatrix("je-d-02.03.02.03.xlsx")
x = excel(12:39,2)
y = excel(42:69,6)
z = x
y(isnan(y))=0;
[Ux,iax,ixx] = unique(x)
[Uy,iay,ixy] = unique(y)
N = 25 % einstellen
xv = linspace(min(x),max(x),N)
yv = linspace(min(y),max(y),N)
[Xm,Ym] = ndgrid(xv,yv)
Zm = griddata(x, y, z, Xm, Ym)
figure
surfc(Xm, Ym, Zm)
grid on
hold on
xlabel('Jahre')
ylabel('Transport in Mio t')
zlabel('Jahre')
title('3D-Grafik: Gegenüberstellung der Emissionen Transport & Internationaler Luft- und Schiffsverkehr')
legend('Jahre','Transport','Jahre')
%% Zweiter Plot
y2 = excel(72:99,16)
y2(isnan(y2))=0;
[Uy2,iay2,ixy2] = unique(y2)
y2v = linspace(min(y2),max(y2),N)
[Xm,Ym2] = ndgrid(xv,y2v)
Zm2 = griddata(x, y2, z, Xm, Ym2)
surfc(Xm, Ym2, Zm)
2 Kommentare
Mathieu NOE
am 21 Jun. 2023
why don't you simply 2D plot the data (Emissions transport (28x1), Emissions Flug-Schiffsverkehr (28x1)) vs. the years ?
Akzeptierte Antwort
Mathieu NOE
am 21 Jun. 2023
i believe that should be sufficient for what we need
pay attention to your row and column indexes when you import data (here with readmatrix) as this does not reflect how it's done inside the excel spreadsheet !
here a code with more robust data management
also you could have different x1 and x2 range (years) , that would not be a problem for the plot itself
data = readmatrix("je-d-02.03.02.03.xlsx");
% important NB : data will be read after the first 11 header lines so there is a
% shift in row index vs when you look at the excel file directly
row_shift = 11;
%% Erster Plot
% data 1 : Transport (ohne internationalen Flugverkehr)
rows = (42:69)-row_shift; % remember NB above !!
col = 2;
x1 = data(rows,col); % years (x axis)
y1 = data(rows,col+4); % CO2-Äquivalente 2)Total (y axis)
%% Zweiter Plot
% data 2 : TInternationaler Flug- und Schiffsverkehr )
rows = (72:99)-row_shift; % remember NB above !!
col = 12;
x2 = data(rows,col); % years (x axis)
y2 = data(rows,col+4); % CO2-Äquivalente 2)Total (y axis)
plot(x1,y1,x2,y2);
xlabel('Jahre')
ylabel('CO2-Äquivalente Mio. t')
title('2D-Grafik: Gegenüberstellung der Emissionen Transport & Internationaler Luft- und Schiffsverkehr')
legend('Transport','Internationaler Flug- und Schiffsverkehr')
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!