【问题标题】:shading and masking over pcolor in matlab在matlab中对pcolor进行着色和遮罩
【发布时间】:2012-05-18 02:32:35
【问题描述】:

确实是两个问题,但我觉得它们重叠,所以我会在一个地方问它们(如果可以的话)。

我在 matlab 中使用以下方法创建了一个 pcolor:

p = pcolor(Lon', Lat', data);

但现在我想补充一些信息。我有一个矩阵mask,它与数据具有相同的维度,但由 1 和 0 填充。在它包含 1 的地方,我想保留 pcolor 中的像素,当它包含 0 时,将其移除(不仅仅是将值变为零,这在我的颜色图中不是由白色像素表示的)。

其次,我有第二个矩阵,称为“点画”,它再次包含 0 和 1。我现在想用点画效果覆盖由 1 表示的任何位置。

这样做的目的是创建一个像这样的图像: http://www.ipcc.ch/publications_and_data/ar4/wg1/en/figure-spm-7.html 绘制平均值的地方,但有太多分歧的区域被涂白,而有很多共识的区域被“点画”。

提前致谢!

【问题讨论】:

    标签: matlab overlay mask stipple


    【解决方案1】:

    我会采取的方法是使用你的面具来提高透明度。这对于pcolor 来说稍微复杂一些,因为它不允许您在创建绘图时直接设置属性,但您可以抓住它的句柄并这样做。

    要覆盖点画,您可以只使用hold on,这样 pcolor 绘图就不会消失,并使用 'plot' 在您想要的位置绘制点。

    Lon = (-179:1:180)'; %# comment for formatting'
    Lat = -90:1:90;
    data = randn(length(Lon),length(Lat)); #% generate random data
    mask = randi(2,size(data))-1; #% generate a random mask (zeros and ones)
    point_matrix = randi(4,size(data)-1)==4; #% random (logical) matrix
    [r c]=find(point_matrix==1); %# get the coordinates of the ones
    figure;
    hold on;
    #% save a handle to the surface object created by pcolor
    h=pcolor(repmat(Lon ,1,length(Lat)),repmat(Lat,length(Lon),1),data);
    #% set properties of that surface: use mask as alphadata for transparency
    #% and set 'facealpha' property to 'flat', and turn off edges (optional)
    set(h,'alphadata',mask,'facealpha','flat','edgecolor','none');
    #% overlay black dots on the center of the randomly chosen tiles
    plot(r-179.5,c-89.5,'.k')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-05-25
      • 1970-01-01
      • 2013-04-05
      • 2020-12-19
      • 1970-01-01
      • 2015-03-23
      • 2013-07-23
      • 1970-01-01
      相关资源
      最近更新 更多