Effacer les filtres
Effacer les filtres

Combining two plots and adding color to points

3 vues (au cours des 30 derniers jours)
TS
TS le 5 Mai 2015
matrix=load('Data');
x = matrix(:,1);
y = matrix(:,2);
fprintf('The maximum distance between two points is %3.2f units.\n',hypot((max(x)-min(x)), (max(y)-min(y))))
plot([max(x),max(y)],[min(x),min(y)])
scatter(x,y)
title('Maximum Distace Achieved')
xlabel('X Values')
ylabel('Y Values')
I'm having two problems with this code: the first is that I somehow need to combine a plot with a scatterplot and the second is that the line in the plot needs to be red while all other points need to be blue. I would try to work with the colors myself but all explanations I've looked up on how to do color for a plot have been rather vague. So if you could help I would greatly appreciate it.

Réponse acceptée

Image Analyst
Image Analyst le 5 Mai 2015
Modifié(e) : Image Analyst le 5 Mai 2015
Get rid of scatter and have two calls to plot
% Plot red lines between the two most separated points.
plot(plot([max(x),max(y)],[min(x),min(y)]), 'r-', 'LineWidth', 2);
hold on
% Plot blue stars at the points.
plot(x, y, 'b*', 'MarkerSize', 10);
grid on;

Plus de réponses (0)

Catégories

En savoir plus sur Scatter Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by