How to plot a trajectory with varying colour?

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

 Réponse acceptée

"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 commentaires

Thank you @Voss for the explanation, but in this case y is a function of x.
Here I have the coordinates of the object (x,y) and would like to measure error in comparison with ground truth. So this method unfortunately does not work. can you please refer to the files attached in the previous comment?
Thanks for the effort.
Voss
Voss le 24 Fév 2023
Modifié(e) : Voss le 24 Fév 2023
Your variables are column vectors; the variables in my examples were row vectors. Easy enough to make it work. See below.
load('test_files_Data.mat')
Error = sqrt((RPS_E-GPS_E).^2+(RPS_N-GPS_N).^2);
mean_Error = mean(Error,1);
Error_std = Error - mean_Error;
x = GPS_E;
y = GPS_N;
c = Error_std;
surface([x x],[y y],[c c],'FaceColor','none','EdgeColor','interp','LineWidth',2);
colormap(jet());
cb = colorbar();
ylabel(cb,'"Error_std"','Interpreter','none')
That's what I'm looking for, thank you for the help, that was a silly mistake on my part.
Cheers!!
Thank you @Voss
Voss
Voss le 24 Fév 2023
You're welcome!

Connectez-vous pour commenter.

Plus de réponses (2)

Cameron
Cameron le 23 Fév 2023
Modifié(e) : Cameron le 23 Fév 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 commentaires

John D'Errico
John D'Errico le 23 Fév 2023
Modifié(e) : John D'Errico le 23 Fév 2023
My gut said oh, sure. This must be possible, probably using line. Line should accept a color spec at each point along the line. It just makes sense this is where I would find it, with one of the possibiities for the 'color' property would be the colors to use. Then I checked. Time for a feature request. :)
@Cameron Thanks for the quick response. Due to confidentiality, I couldn't share the actual trajectory (which covers an area of 9 square Kilometer). So the plot is huge and contains many data points.
In your solution, I cannot assign colour to the error value, so I cannot visualize the error properly, so I don't think this is the right solution.
Appreciate your effort, Thanks
@John D'Errico Thanks for understanding my question i.e., using colors to represent underlying data is what I'm looking for.
Cheers for the comment.

Connectez-vous pour commenter.

Les Beckham
Les Beckham le 23 Fév 2023

0 votes

Take a look at this Answer which shows a trick for doing this using surface.

5 commentaires

I have tried this initially, but unfortunately couldn't work with it. I'm trying to assign an independent variable to a data point in 2D through colour.
Les Beckham
Les Beckham le 23 Fév 2023
If you provide more details (your data and the code you are using to plot it, and the exact errors or undesired behavior you are seeing) someone can probably help work out the issues you are having.
Maheedhar Korimi
Maheedhar Korimi le 24 Fév 2023
Modifié(e) : Maheedhar Korimi le 24 Fév 2023
Please refer the attachments for data! My apologies for the delay.
Thank you
Les Beckham
Les Beckham le 24 Fév 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)?
I have attached the code and data in my previous comment, please run it, you'll see a trajectory(radar) with errors (> 99 percentile) in comparision with GPS data, represented as marker indices.
So, instead of representing the errors as marker indices, I would like to show the errors in the form of colour (maybe of colourmap: jet), where blue represents low error and red represents high error in the data.
If you have any further questions, please feel free to ask.
My apologies if I haven't communicated properly.

Connectez-vous pour commenter.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by