How can I plot two variables with the line color varying as the third variable?
49 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Joan Vazquez
il 30 Mar 2020
Same need, this is so easy in e.g. R, no idea in Matlab...did you solve it?
Risposte (2)
KSSV
il 11 Set 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);
darova
il 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)
0 Commenti
Vedere anche
Categorie
Scopri di più su Colormaps in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!