How can I plot 2D surface plot with color bar
12 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Ambali Odebowale
am 12 Dez. 2022
Kommentiert: Star Strider
am 12 Dez. 2022
I have an excel file containing 3 variables as attached. I want to plot the variables as a 2D surface plot with the third column representing the color bar. I also attach an example of the plot I am trying to plot.
When I used surf command, I get this error:
Error using surf (line 71)
Z must be a matrix, not a scalar or vector.
Error in PTC_calculation (line 74)
surf(w_ev,beta,PTC)
Thanks
1 Kommentar
KSSV
am 12 Dez. 2022
You cannot plot a surface plot with the data you have.
T = readtable('https://in.mathworks.com/matlabcentral/answers/uploaded_files/1227857/DATA.xlsx') ;
x = T.w ;
y = T.beta ;
z = T.PTC ;
scatter(x,y,[],z)
Akzeptierte Antwort
Star Strider
am 12 Dez. 2022
Bearbeitet: Star Strider
am 12 Dez. 2022
It is possible to create a surface plot from it, however it is probably not worth the effort —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1227857/DATA.xlsx')
figure
stem3(T1{:,1}, T1{:,2}, T1{:,3})
xlabel('w')
ylabel('\beta')
view(60,30)
title('Original Data')
N = size(T1,1)*10;
wv = linspace(min(T1.w), max(T1.w), N);
betav = linspace(min(T1.beta), max(T1.beta), N);
PTCv = linspace(min(T1.PTC), max(T1.PTC), N);
[Wm,Bm] = ndgrid(wv, betav);
PTCm = griddata(T1.w, T1.beta, T1.PTC, Wm, Bm);
PTCm(isnan(PTCm)) = 0;
figure
surf(Wm, Bm, PTCm, 'EdgeColor','interp', 'FaceAlpha',0.5)
colormap(turbo)
colorbar
xlabel('w')
ylabel('\beta')
view(60,30)
title('Interpolated Surface Plot Of Original Data')
figure
surf(Wm, Bm, PTCm, 'EdgeColor','interp', 'FaceAlpha',0.5)
colormap(turbo)
colorbar
xlabel('w')
ylabel('\beta')
view(-15,45)
title('Interpolated Surface Plot Of Original Data')
EDIT — Corrected typograp[hical errors.
.
6 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graph and Network Algorithms 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!