【发布时间】:2016-10-27 21:36:28
【问题描述】:
我想在我正在创建的图形上绘制矩形。我也希望能够用透明颜色填充该矩形。所以我使用“补丁”而不是“矩形”,这将允许我这样做。
我能够在我想要的位置和大小中获得矩形,但我似乎无法以我认为应该工作的方式填充透明度?
在文档中,格式为:
p=patch(X,Y, 'c')
当我输入它时,它从不考虑由“c”/青色表示的颜色,只会绘制一个标准的黑色矩形。但是,我可以使用以下点索引表示法设置颜色:
p.EdgeColor='c';
我的实际脚本不同,因为 X 和 Y 是可变的,但我在此处附加了一个非常简单的脚本来模拟我的矢量化绘图问题。它只是在每 10 个位置创建 Xs 个顶点,宽度为 2,高度为 10。
我是否滥用了 patch 函数来让它用 FaceAlpha 填充透明颜色?
clear all;
% Generate some simple X value data, where each X is the X value starting from the
% lower left of the rectangle, in a clockwise fashion around the edges of
% rectangle.
X1(:,1) = 0:10:100;
X2(:,1) = 0:10:100;
X3(:,1) = X1+2;
X4(:,1) = X1+2;
% Rotate the X vectors into rows.
X1 = X1(:)';
X2 = X2(:)';
X3 = X3(:)';
X4 = X4(:)';
% Here I am stacking each X on top of each other, and padding the bottom
% row with NaNs. Adding a similar Y set of values, which will simply be a
% height of 0-10
X =[X1; X2; X3; X4;
nan(size(X1)) ];
Y =[zeros(size(X1)); 10+zeros(size(X2)); ...
10+zeros(size(X3)); zeros(size(X4));
nan(size(X1)) ];
% Rotate vectors so that the last value in the X/Y coordinates is a NaN,
% and Matlab will ignore and plot the next value
X=X(:);
Y=Y(:);
% This Plots the outline of the rectangles I am looking for, with a width
% of 2, height of 10, starting at each 10th value of X
p=patch( X ,Y,'c');
p.EdgeColor = 'b'; %Comment this out to see that the Patch function is not working?
p.FaceColor = 'blue';
p.FaceAlpha = 0.5;
% But for some reason it is not FILLING in the rectangles/patches I have
% drawn?
【问题讨论】:
标签: matlab plot matlab-figure patch rectangles