How to use a colorbar with cmapline correctly?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi, I find using a colorbar with cmapline does bizarre things. Try this code, which just plots vertical lines at integer locations from 1 to 60:
t(1,1:60)=1:60;
for k=2:10;
t(k,:)=t(1,:);
end
test_z=1:10;
plot(t,-test_z)
xlim([0 60]);
cmapline('colormap',jet);
h=colorbar;
I would have thought the lines should go from blue (x=1) to red (x=60) as we go from left to right. But I see the opposite.
If you plot the colorbar, however, it increases from blue to red. Now if you delete the colorbar, flip the colormap:
cmapline('colormap',flipud(jet));
and plot the colorbar again, it is still increasing from blue to red although the lines now go from blue to red as we go from left to right! Can somebody tell me what's going on? Thanks!
0 comentarios
Respuestas (1)
Mudambi Srivatsa
el 29 de Sept. de 2016
I understand that the lines go from red(x=1) to blue(x=60) as you go from left to right when the "cmapline" function is used with 'jet' colormap. This is the expected behavior of the "cmapline" function.
"cmapline" uses "findobj" function to get the line object handles.
>> lh=num2cell(findobj(ax,'type','line'));
When a standard colormap is specified, it used "feval" to get the color values.
>> colrs=num2cell(feval(cmap,numlines),2);
However, when you specify the colormap as 'flipud(jet)', it follows a different workflow to generate colors. Then, it assigns the colors to the lines as a one-one mapping between 'lh' and 'colrs'.
>> cellfun(@(x,y)(set(x,'color',y)),lh,colrs);
The reason you see the lines go from red to blue using 'jet' colormap is because 'lh' contains the line handles in a reverse order. "findobj" does not guarantee any specific order and in this case returns line handles from right to left.
Further, the colorbar increases from blue to red in both cases because you are not updating it after "cmapline" function. The following code snippet updates the "colorbar" and displays it.
>> [lh, cmap] = cmapline('colormap',jet);
>> colormap(cmap);
>> h = colorbar;
However, you notice different color mapping between "colorbar" and the actual lines due to the implementation of the "cmapline" as explained above. One possible workaround in this case is to flip the 'cmap' before updating the colorbar.
>> colormap(flipud(cmap));
>> h = colorbar;
I suggest you to contact the author of the file exchange submission for additional questions.
0 comentarios
Ver también
Categorías
Más información sobre Colormaps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!