\n
By considering my example image, I would want to add the array of constants in the lateral bar and then to color each curve according the lateral bar.
\n% Family of 50 planar Lyapunov orbits around L1 in dimensionless unit\nfig = figure;\n\nfor k1 = 1:(numel(files_L1_L2_Ly_prop)-2)\n plot([Ly_orb_filt(1).prop(k1).orbits.x],[Ly_orb_filt(1).prop(k1).orbits.y],...\n "Color",my_green*1.1); hold on %"Color",my_green*1.1\n colorbar()\nend\naxis equal\n\n\n% Plot L1 point\nplot(Ly_orb_filt_sys_data(1).x,Ly_orb_filt_sys_data(1).y,'.',...\n 'color',[0,0,0],'MarkerFaceColor',my_green,'MarkerSize',10);\ntext(Ly_orb_filt_sys_data(1).x-0.00015,Ly_orb_filt_sys_data(1).y-0.0008,'L_{1}');\n\n%Primary bodies plots \nplot(AstroData.mu_SEM_sys -1,0,'.',...\n 'color',my_blue,'MarkerFaceColor',my_blue,'MarkerSize',20);\ntext(AstroData.mu_SEM_sys-1,0-0.001,'$Earth + Moon$','Interpreter',"latex"); \n\ngrid on;\nxlabel('$x$','interpreter','latex','fontsize',12);\nylabel('$y$','interpreter','latex','FontSize',12);\n
\nHow can I color each line based on its Jacobi constant value?
\n","author":{"@type":"Person","name":"g_don"},"upvoteCount":0,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"You can use any colour map to produce a series of RGB-triplets for the plotting routines to read (Or create an m-by-3 matrix with elements between 0
and 1
yourself):
n = 10; % Plot 10 lines\nx = 1:15;\ncolour_map = jet(n); % Get colours. parula, hsv, hot etc.\n\nfigure;\nhold on\nfor ii = 1:n\n % Plot each line individually\n plot(x, x+ii, 'Color', colour_map(ii, :))\nend\n\ncolorbar % Show the colour bar.\n
\nWhich on R2007b produces:
\n\nNote that indexing into a colour map will produce linearly spaced colours, thus you'll need to either interpolate or calculate a lot to get the specific ones you need. Then you can (need to?) modify the resulting colour bar's labels by hand to reflect your input values. I'd simply use parula(50)
, treat its indices as linspace(jacobi(1), jacobi(end), 50)
and then my_colour = interp1(linspace(jacobi(1), jacobi(end), 50), parula(50), jacobi)
.
So in your code, rather than using "Color",my_green*1.1
for each line, use "Color",my_colour(kl,:)
, where my_colour
is whatever series of RGB triplets you have defined.
Reputation: 197
I produced a plot that contains 50 curves and each of them corresponds to a specific value of a parameter called "Jacobi constant", so I have 50 values of jacobi constant stored in array called jacobi_cst_L1
:
3.000900891023230
3.000894276927840
3.000887643313580
3.000881028967010
3.000874419173230
3.000867791975870
3.000861196034850
3.000854592397690
3.000847948043080
3.000841330136040
3.000834723697250
3.000828099771820
3.000821489088600
3.000814922863360
3.000808265737810
3.000801695858850
3.000795067776960
3.000788475204760
3.000781845363950
3.000775192199620
3.000768609354090
3.000761928862980
3.000755335851910
3.000748750854930
3.000742084743060
3.000735532899990
3.000728906460450
3.000722309400740
3.000715644446600
3.000709016645110
3.000702431180730
3.000695791284050
3.000689196186970
3.000682547292110
3.000675958537960
3.000669315388860
3.000662738391370
3.000656116141060
3.000649560630930
3.000642857256680
3.000636330415510
3.000629657944820
3.000623060310100
3.000616425935580
3.000609870077710
3.000603171772120
3.000596554947660
3.000590018845460
3.000583342259840
3.000576748353570
I want to use a colormap to color my curves and then show in a lateral bar the legend that show the numerical values corresponding to each color of orbit.
By considering my example image, I would want to add the array of constants in the lateral bar and then to color each curve according the lateral bar.
% Family of 50 planar Lyapunov orbits around L1 in dimensionless unit
fig = figure;
for k1 = 1:(numel(files_L1_L2_Ly_prop)-2)
plot([Ly_orb_filt(1).prop(k1).orbits.x],[Ly_orb_filt(1).prop(k1).orbits.y],...
"Color",my_green*1.1); hold on %"Color",my_green*1.1
colorbar()
end
axis equal
% Plot L1 point
plot(Ly_orb_filt_sys_data(1).x,Ly_orb_filt_sys_data(1).y,'.',...
'color',[0,0,0],'MarkerFaceColor',my_green,'MarkerSize',10);
text(Ly_orb_filt_sys_data(1).x-0.00015,Ly_orb_filt_sys_data(1).y-0.0008,'L_{1}');
%Primary bodies plots
plot(AstroData.mu_SEM_sys -1,0,'.',...
'color',my_blue,'MarkerFaceColor',my_blue,'MarkerSize',20);
text(AstroData.mu_SEM_sys-1,0-0.001,'$Earth + Moon$','Interpreter',"latex");
grid on;
xlabel('$x$','interpreter','latex','fontsize',12);
ylabel('$y$','interpreter','latex','FontSize',12);
How can I color each line based on its Jacobi constant value?
Upvotes: 0
Views: 587
Reputation: 18197
You can use any colour map to produce a series of RGB-triplets for the plotting routines to read (Or create an m-by-3 matrix with elements between 0
and 1
yourself):
n = 10; % Plot 10 lines
x = 1:15;
colour_map = jet(n); % Get colours. parula, hsv, hot etc.
figure;
hold on
for ii = 1:n
% Plot each line individually
plot(x, x+ii, 'Color', colour_map(ii, :))
end
colorbar % Show the colour bar.
Which on R2007b produces:
Note that indexing into a colour map will produce linearly spaced colours, thus you'll need to either interpolate or calculate a lot to get the specific ones you need. Then you can (need to?) modify the resulting colour bar's labels by hand to reflect your input values. I'd simply use parula(50)
, treat its indices as linspace(jacobi(1), jacobi(end), 50)
and then my_colour = interp1(linspace(jacobi(1), jacobi(end), 50), parula(50), jacobi)
.
So in your code, rather than using "Color",my_green*1.1
for each line, use "Color",my_colour(kl,:)
, where my_colour
is whatever series of RGB triplets you have defined.
Upvotes: 4