matlab曲面图 - 标记颜色条和更改轴值

时间:2012-10-15 20:06:28

标签: matlab graph label geometry-surface

我正在尝试使用彩条在matlab中绘制3D表面图。

我想知道如何

  1. 标记颜色栏的标题

  2. 更改轴刻度标签

  3. 我的代码的重要部分是

    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)
    

    enter image description here 我试图将for循环的间隔中的x和y轴刻度更改为代表每个间隔的实际数字。

    我似乎无法在文档中找到上述任何内容。

1 个答案:

答案 0 :(得分:2)

以下代码显示如何更改Xticks,Yticks以及为颜色条的值添加标签:

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

enter image description here

使用此代码,您可以更改第一个YTickLabel以设置颜色条标题(嗯,类似):

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

enter image description here

我的colorbar命令代码基于:http://www.mathworks.es/es/help/matlab/ref/colorbar.html

希望这会有所帮助,我会尝试将标题添加到颜色栏......