⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 discretecolorbar.m

📁 JLAB is a set of Matlab functions I have written or co-written over the past fifteen years for the p
💻 M
字号:
function[hc]=discretecolorbar(hc,cax,ci,str)%DISCRETECOLORBAR  Plots a colorbar with discrete variation.%%   In filled contour plots one has discrete values of color (or of%   shading), but the colorbar resulting from Matlab's COLORBAR command    %   has a continuous spectrum of color.                                   %                                                                         %   DISCRETECOLORBAR(HC,CAX,CI) where HC is a handle to a colorbar axis   %   (i.e. from calling HC=COLORBAR), CAX=[CMIN CMAX] are the color axis   %   limits, and CI is a vector of contour intervals, redraws the colorbar %   with discrete breaks at values CI and axis limits CAX.                %                                                                         %   DISCRETECOLORBAR(HC,CAX,CI,STR) where STR is either 'hori' or 'vert'  %   specifies whether the colorbar should have a horizontal or vertical   %   orientation; STR defaults to 'vert'.                                  %                                                                         %   Make sure to set the color axis of the contour plot is also is set    %   to CAX [via CAXIS(CAX)].                                               %   _________________________________________________________________%   This is part of JLAB --- type 'help jlab' for more information %   (C) 2001, 2004 J.M. Lilly --- type 'help jlab_license' for details    %discretecolorbar(hc,cax,ci,'vert')%Matlab is shit... I should not have to do this.if nargin==3   str='vert';end%axes(hc),set(gca,'xtick',[],'ytick',[],'visible','off')%xlabel(''),ylabel('')%pos=get(hc,'position');xal=get(hc,'xaxislocation');yal=get(hc,'yaxislocation');%hc=axes('position',pos);set(hc,'userdata',[])axes(hc)mat=[0:127]';mat=mat/127*(cax(2)-cax(1))+cax(1);if strcmp(str(1:4),'vert')   contourf([0 1],mat,[mat mat],ci);   axis([0 1 cax(1) cax(2)])   set(gca,'ytick',ci,'xtick',[])elseif strcmp(str(1:4),'hori')   contourf(mat,[0 1],[mat';mat'],ci);   axis([cax(1) cax(2) 0 1])   set(gca,'xtick',ci,'ytick',[])endset(hc,'xaxislocation',xal);set(hc,'yaxislocation',yal);set(hc,'box','on','layer','top'),grid offcaxis(cax)%figure,plot(1:10),hc=colorbar;discretecolorbar(hc,cax,ci,'vert');%caxis([2.5 5.5]) %ci=[cax(1):.4:cax(2)]

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -