How to set arbitrary colors for bars in a 3D bar plot?

前端 未结 3 442
渐次进展
渐次进展 2021-01-14 08:58

Say that I have a matrix Z with some values, and I want to illustrate it by a plotting the values in Z by height. The first solution comes to mind

3条回答
  •  甜味超标
    2021-01-14 09:17

    This is a partial answer.

    The case of using the bar height as color is covered by the official MATLAB documentation. Essentially the example code boils down to:

    function q45423394
    hB = bar3(peaks(25)); colorbar;
    for indE = 1:numel(hB)
      hB(indE).CData = hB(indE).ZData;
    end
    

    All you need to do afterwards is make sure that the colormap is the one you want.

提交回复
热议问题