随着HG2图形(R2014b +),你可以得到一些无证底层情节的对象,并改变透明度。
c = colorbar();
% Manually flush the event queue and force MATLAB to render the colorbar
% necessary on some versions
drawnow
alphaVal = 0.1;
% Get the color data of the object that correponds to the colorbar
cdata = c.Face.Texture.CData;
% Change the 4th channel (alpha channel) to 10% of it's initial value (255)
cdata(end,:) = uint8(alphaVal * cdata(end,:));
% Ensure that the display respects the alpha channel
c.Face.Texture.ColorType = 'truecoloralpha';
% Update the color data with the new transparency information
c.Face.Texture.CData = cdata;
你必须要小心,这样做的彩条是不断刷新,这些变化不会粘。为了让他们留下来,而我打印的身影,我只是改变了Face
的东西的ColorBinding
模式除了interpolated
c.Face.ColorBinding = 'discrete';
这意味着,当你改变颜色限制或颜色表也不会被更新。如果您想更改其中的任何一项,则需要将ColorBinding
重置为intepolated
,然后再次运行上述代码。
c.Face.ColorBinding = 'interpolated';
例如,以下将与一个透明颜色条保存的图像两个色彩映射表:
c = colorbar();
drawnow;
alphaVal = 0.1;
% Make the colorbar transparent
cdata = c.Face.Texture.CData;
cdata(end,:) = uint8(alphaVal * cdata(end,:));
c.Face.Texture.ColorType = 'truecoloralpha';
c.Face.Texture.CData = cdata;
drawnow
% Make sure that the renderer doesn't revert your changes
c.Face.ColorBinding = 'discrete';
% Print your figure
print(gcf, 'Parula.png', '-dpng', '-r300');
% Now change the ColorBinding back
c.Face.ColorBinding = 'interpolated';
% Update the colormap to something new
colormap(jet);
drawnow
% Set the alpha values again
cdata = c.Face.Texture.CData;
cdata(end,:) = uint8(alphaVal * cdata(end,:));
c.Face.Texture.CData = cdata;
drawnow
% Make sure that the renderer doesn't revert your changes
c.Face.ColorBinding = 'discrete';
print(gcf, 'Ugly_colormap.png', '-dpng', '-r300');
你尝试'HB =彩条; alpha(hb,.1);'? –
@MadPhysicist是的,这是行不通的。 – machinery