Colorbar Limits not related to plot in R2018a
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Dear All,
I am trying to create bar plots and add a color bar. It's a bit of a special setting, because I want each bar to have the face color corresponding to its height in a chosen color map. In R2017a, adding a color bar and resetting the labels works well. The exact same code in 2018a launches an error.
Data:
Range of values (used for coloring the bar according to color map): 1 to 256, mapped from -0.15 to 0.15.
In the color bar, I want the limits to be -0.15 - 0.15 and not 1 - 256, so I need to change them.
Limits of color bar in 2017a: [1 50 100], reflecting half negative values and half positive values (50 representing the 0 in the color map).
Limits of color bar in 2018a: [0 1], with ticks and labels that do not reflect the values in the bar plot.
h = plot_data(axmat,minsl:maxsl,weights(minsl:maxsl),cols,valsN(minsl:maxsl),[minw maxw]);
hc = colorbar('Units','normalized','Position',[0.85 0.2 0.02 0.7]);
% Change colorbar limits and tick labels
try
limhc = get(hc,'Limits');
newticksproj = ceil(newticks * (max(limhc)/size(cols,1)));
set(hc,'Ticks',newticksproj);
set(hc,'TickLabelsMode','manual');
set(hc,'TickLabels',labels);
catch
newticksproj = [0 1];
set(hc,'Ticks',newticksproj);
set(hc,'TickLabelsMode','manual');
set(hc,'YTickLabels',cellstr(num2str(labels)))
end
With plot_data being an inhouse routine that maps each value (between -0.15 to 0.15) to an integer in the range 1-256 and performs a bar plot.
So when I get the 'newticksproj' in R2018a, they are [1 1 1] instead of [1 50 100], and it is hence a non-increasing vector and the code fails.
Important note: I need this code (and potential solutions) to work on older and newer version of Matlab as it is part of a toolbox (as soon as R2007a). Matlab compatibility issues have really been painful...
0 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre 2-D and 3-D Plots 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!