Mit HG2 Grafiken (R2014b +) können Sie einige der Menschen ohne Papiere zugrunde liegenden Handlung Objekte erhalten und die Transparenz verändern.
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;

Du musst vorsichtig tun, dies sein, da die colorbar kontinuierlich aktualisiert werden und diese Änderungen werden nicht bleiben. Um sie zu erhalten bleiben, während ich die Figur gedruckt, Ich habe gerade den ColorBinding
Modus des Face
auf etwas anderes als interpolated
c.Face.ColorBinding = 'discrete';
Das bedeutet, dass es nicht aktualisiert werden, wenn Sie die Farbgrenzen oder die colormap ändern. Wenn Sie eines dieser Dinge ändern möchten, müssen Sie die ColorBinding
auf intepolated
zurücksetzen und dann den obigen Code erneut ausführen.
c.Face.ColorBinding = 'interpolated';
Zum Beispiel folgende würde ein Bild mit einem transparenten colorbar für zwei Farbtabellen speichern:
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');
Haben Sie versucht, 'hb = colorbar; Alpha (hb, .1); '? –
@MadPhysicist Ja, das funktioniert nicht. – machinery