How to plot a trajectory with varying colour?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Maheedhar Korimi
am 23 Feb. 2023
Kommentiert: Voss
am 24 Feb. 2023
I'm trying to plot the trajectory which also shows error characteristics visually.
Inputs: East(m), North(m), error(m)
error = sqrt((East_radar - North_GPS)^2 + (East_GPS - North_GPS)^2)
At present, I'm able to plot trajectory, with the marker indices representing the points where the error is high. I have implemented the code as seen below.
To make this visualization better, how can I represent the trajectory with varying colour representing error value? as shown below.
So, higherror represents Red and low error represents Green? Your assistance would relly help me.Thanks!
If my query is unclear, please revert.
figure()
plot(Radar_East, Radar_North,'LineStyle','-')
xlabel('East (m)')
ylabel('North (m)')
title('GPS EN plot')
hold on
plot(Radar_East(outliers),Radar_North(outliers),'o','MarkerSize',8);
legend('RADAR Trajectory','Outliers > 99 percentile')
hold off
0 Kommentare
Akzeptierte Antwort
Voss
am 23 Feb. 2023
"I'm trying to assign an independent variable to a data point in 2D through colour."
You can choose any colour(s) you like.
Examples:
x = linspace(0,2*pi);
y = sin(x);
subplot(3,2,1)
c = x;
surface([x;x],[y;y],[c;c],'FaceColor','none','EdgeColor','interp','LineWidth',2);
title('color = x')
subplot(3,2,2)
c = y;
surface([x;x],[y;y],[c;c],'FaceColor','none','EdgeColor','interp','LineWidth',2);
title('color = y')
subplot(3,2,3)
c = cos(x);
surface([x;x],[y;y],[c;c],'FaceColor','none','EdgeColor','interp','LineWidth',2);
title('color = cos(x)')
subplot(3,2,4)
c = y.^2;
surface([x;x],[y;y],[c;c],'FaceColor','none','EdgeColor','interp','LineWidth',2);
title('color = y^2')
subplot(3,2,5)
c = x.^2-4*pi^2*y.^2;
surface([x;x],[y;y],[c;c],'FaceColor','none','EdgeColor','interp','LineWidth',2);
title('color = x^2-4*pi^2*y^2')
subplot(3,2,6)
c = rand(size(x));
surface([x;x],[y;y],[c;c],'FaceColor','none','EdgeColor','interp','LineWidth',2);
title('color = random')
figure
colormap(copper())
subplot(3,2,1)
c = x;
surface([x;x],[y;y],[c;c],'FaceColor','none','EdgeColor','interp','LineWidth',2);
title('color = x')
subplot(3,2,2)
c = y;
surface([x;x],[y;y],[c;c],'FaceColor','none','EdgeColor','interp','LineWidth',2);
title('color = y')
subplot(3,2,3)
c = cos(x);
surface([x;x],[y;y],[c;c],'FaceColor','none','EdgeColor','interp','LineWidth',2);
title('color = cos(x)')
subplot(3,2,4)
c = y.^2;
surface([x;x],[y;y],[c;c],'FaceColor','none','EdgeColor','interp','LineWidth',2);
title('color = y^2')
subplot(3,2,5)
c = x.^2-4*pi^2*y.^2;
surface([x;x],[y;y],[c;c],'FaceColor','none','EdgeColor','interp','LineWidth',2);
title('color = x^2-4*pi^2*y^2')
subplot(3,2,6)
c = rand(size(x));
surface([x;x],[y;y],[c;c],'FaceColor','none','EdgeColor','interp','LineWidth',2);
title('color = random')
4 Kommentare
Weitere Antworten (2)
Cameron
am 23 Feb. 2023
Bearbeitet: Cameron
am 23 Feb. 2023
I don't think there is a way to do this using just one plot. My quick solution would be to do something like this
x = 0:0.05:2*pi; %sample x data
y = sin(x); %sample y data
c = hsv(length(x)); %hsv values over the length of x
hold on %hold the graph
for ii = 1:length(x)-1
plot(x(ii:ii+1),y(ii:ii+1),'-','Color',c(ii,:)) %plot
end
hold off
Not the most elegant solution, but if really want to do it, this is a way. One problem with this approach would be if you have few data points. You could spline or smooth your data though.
3 Kommentare
Les Beckham
am 23 Feb. 2023
Take a look at this Answer which shows a trick for doing this using surface.
5 Kommentare
Les Beckham
am 24 Feb. 2023
"provide more details (your data and the code you are using to plot it".
Are we supposed to guess what you are trying to plot (and how)?
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots 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!