Save a contourf plot with transparent background and text labels
조회 수: 3 (최근 30일)
이전 댓글 표시
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
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!