How can I plot two variables with the line color varying as the third variable?

39 vues (au cours des 30 derniers jours)
Bridger Baird
Bridger Baird le 11 Sep 2018
Réponse apportée : darova le 30 Mar 2020
My goal is to plot two variables, and vary the color of the lines by the third variable. I've done this before using scatter easily with the following code:
figure(2)
scatter(dist,geoPga,[],mag,'filled')
c = colorbar;
c.Label.String = 'Moment Magnitude, Mw'
xlabel('Hypocentral Distance to Station (km)')
ylabel('Geometric PGA (cm/s/s)')
title('Geometric PGA vs. Distance to Station')
But trying something similar with plot doesn't seem to work... Here is what I have tried so far...
figure(1)
plot(1./T,ScaledSa,[],log10stddev,'Filled')
c = colorbar;
c.Label.String = 'Standard Deviation'
title('Target Spectrum & Scaled
Records','FontWeight','bold','FontSize',14)
xlabel('Frequency (Hz)','FontWeight','bold','FontSize',12)
ylabel('PSA (cm/s/s)','FontWeight','bold','FontSize',12)
xlim([0 50])
hold on
Essentially, I'm trying to show the standard deviation as the third variable... With a certain color lines representing small standard deviations, and a gradient of different colors up to a high standard deviation.
Any tips?
  1 commentaire
Joan Vazquez
Joan Vazquez le 30 Mar 2020
Same need, this is so easy in e.g. R, no idea in Matlab...did you solve it?

Connectez-vous pour commenter.

Réponses (2)

KSSV
KSSV le 11 Sep 2018
x = linspace(0,2*pi,1000) ;
y = sin(x);
z = zeros(size(x));
c = x; % This is the color, vary with x in this case.
surface([x;x],[y;y],[z;z],[c;c],'facecolor','none','edgecolor','interp','linewidth',2);
  1 commentaire
Bridger Baird
Bridger Baird le 14 Sep 2018
This isn't what I'm looking for. This varies the color along a particular line. I have 68 total lines, and I want each line to be only one color. Each line has an associated standard deviation, and I want to plot the lines with the smallest standard deviation being green, with a scale, up to the largest standard deviation being red.

Connectez-vous pour commenter.


darova
darova le 30 Mar 2020
Use patch
x = linspace(0,10);
y = sin(x);
c = jet(100);
n = length(x);
fv = [1:n-1;2:n]';
patch('faces',fv,'vertices',[x; y]',...
'faceVertexCData',c,...
'edgecolor','flat',...
'linewidth',2)

Catégories

En savoir plus sur Colormaps 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