MATLAB添加色标(colorbar)

 时间:2026-04-24 03:50:10

1、第一,为峰值函数(peaks)的图形添加色标。启动MATLAB,新建脚本,输入如下代码:

close all; clear all; clc

figure(1)

surf(peaks(30))

colorbar('YTickLabel',{'Freezing','Cold','Cool',...

    'Neutral','Warm','Hot','Burning','Nuclear'})

MATLAB添加色标(colorbar)

2、第二,保存和运行上述脚本,得到峰值函数(peaks)的图形(figure 1),并且图形右侧添加了色标。

MATLAB添加色标(colorbar)

3、第三,在上述脚本的基础上,接着输入如下代码:

figure(2)

contourf(peaks(30))

colormap cool

colorbar('location','SouthOutside')

其中('location','southoutside')控制色标处于图形中的位置,还可以取North,South,East,West,Northoutside,Southoutside,Eastoutside,Westoutside。

MATLAB添加色标(colorbar)

4、第四,保存和运行上述脚本,得到图像figure 2,如下图,色标位于图形底部。

MATLAB添加色标(colorbar)

5、第五,利用subplot对上述脚本进行改进,将figure 1与figure 2画在一张图。脚本改进如下:

close all; clear all; clc

%figure(1)

subplot(2,1,1)

surf(peaks(30))

colorbar('YTickLabel',{'Freezing','Cold','Cool',...

    'Neutral','Warm','Hot','Burning','Nuclear'})

%figure(2)

subplot(2,1,2)

contourf(peaks(30))

colormap cool

colorbar('location','SouthOutside')

MATLAB添加色标(colorbar)

6、第六,保存和运行上述改进的脚本,figure 1与figure 2画在一张图,并且均添加了色标(colorbar)。

MATLAB添加色标(colorbar)

  • 用matlab将plot后的图像保存
  • 如何修改matlab绘图中线条的粗细
  • 如何在matlab画的图中改变坐标显示的范围
  • 怎样在matlab图形中添加网格?
  • Matlab 画图 图例大小调整
  • 热门搜索
    hownice什么意思 shine是什么意思 paas是什么意思 什么是精油开背 爱不释手的释是什么意思 尽善尽美的意思 tomato是什么意思 滑雪需要准备什么 保温桶什么牌子好 移舟泊烟渚日暮客愁新的意思