Save a contourf plot with transparent background and text labels
5 views (last 30 days)
Show older comments
I've found this question dealing with the problem of a contourf plot with a transparent background. Basically the answer was found in this blog about undocumented matlab options.
I used the solution provided there but want to add some text labels for the contour plot. I can add these for a plot without any transparency modifications as well as for one with transpareny. Where I struggle is when it comes to saving one of these figures. The issue is best explained with the code below. It is possible to view a contouf plot with text as well as view and save one without text. When I then try to view and afterwards save a contourf plot with text the transparency gets lost during the saving progress.
I kindly ask if someone is able to reproduce this problem e.g. using the code below. And secondly if by chance someone has an idea to save a contourf plot with the option 'ShowText' set to 'on'.
figure
% generate a figure with text and display it -> works
[~, hContour] = contourf(peaks(20), 10,'ShowText','on');
drawnow; % this is important, to ensure that FacePrims is ready in the next line!
hFills = hContour.FacePrims; % array of TriangleStrip objects
[hFills.ColorType] = deal('truecoloralpha'); % default = 'truecolor'
for idx = 1 : numel(hFills)
hFills(idx).ColorData(4) = 50; % default=255
end
figure
% generate a figure without text and display+save it -> works
[~, hContour] = contourf(peaks(20), 10,'ShowText','off');
drawnow; % this is important, to ensure that FacePrims is ready in the next line!
hFills = hContour.FacePrims; % array of TriangleStrip objects
[hFills.ColorType] = deal('truecoloralpha'); % default = 'truecolor'
for idx = 1 : numel(hFills)
hFills(idx).ColorData(4) = 50; % default=255
end
saveas(gcf,"test_no_text.jpg")
figure
% generate a figure with text and display+save it -> doesn't work
[~, hContour] = contourf(peaks(20), 10,'ShowText','on');
drawnow; % this is important, to ensure that FacePrims is ready in the next line!
hFills = hContour.FacePrims; % array of TriangleStrip objects
[hFills.ColorType] = deal('truecoloralpha'); % default = 'truecolor'text as well a
for idx = 1 : numel(hFills)
hFills(idx).ColorData(4) = 50; % default=255
end
saveas(gcf,"test_with_text.jpg")
I'm working with Matlab R2018a.
Edit:
This unsolved issue might be related: https://www.mathworks.com/matlabcentral/answers/514830-adjusting-the-transparency-of-a-contour-plot-using-a-gradient-of-alpha-values
0 Comments
Answers (0)
See Also
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!