Reputation: 187
I am trying to plot a 3D surface plot in matlab with a colorbar.
I would like to know how to
label the title of the colorbar
change the axis tick labels
The important parts of my code are
number_panels = 1:100:500;
number_turbines = 0;
number_batteries = 0:300:1700;
for idx_number_panels = 1:length(number_panels)
for idx_number_turbines = 1:length(number_turbines)
for idx_number_batteries = 1:length(number_batteries)
for h=2:3 %# hours
A = squeeze(total_annual_cost)
B = squeeze(total_renewables_penetration)
figure;
surface(A,B)
I am trying to change the x and y axis ticks from the intervals of the for loop to actual numbers that represent each interval.
I can't seem to find any of the above in the documentation.
Upvotes: 1
Views: 9947
Reputation: 565
The following code shows how to change the Xticks, the Yticks and to add labels to the values of the colorbar:
clear all
close all
clc
h = surface(peaks)
colorbar('YTickLabel',... % set labels to the colorbar
{'Freezing','Cold','Cool','Neutral',...
'Warm','Hot','Burning','Nuclear'})
view(-35,45)
number_panels = 0:5:50;
number_batteries = 0:15:50;
set(gca,'XTick',number_panels) % set Xticks
set(gca,'YTick',number_batteries ) % set Yticks
grid on
With this code you change the first YTickLabel to set a colorbar title (well, something similar):
clear all
close all
clc
number_panels = 0:5:50;
number_batteries = 0:15:50;
h = surface(peaks);
chandle = colorbar;
current_colorbar_labels = get(chandle,'YTickLabel');
current_zticks = get(chandle,'YTick');
aux = cellstr(current_colorbar_labels);
aux{end} = 'Title';
set(chandle,'YTickLabel',aux);
view(-35,45)
set(gca,'XTick',number_panels) % set Xticks
set(gca,'YTick',number_batteries ) % set Yticks
set(gca,'ZTick',current_zticks ) % set Yticks
grid on
My code for the colorbar commands is based on: http://www.mathworks.es/es/help/matlab/ref/colorbar.html
Hope this helps, I will try to add the title to the colorbar...
Upvotes: 2