change only the background color of contour plot
조회 수: 8 (최근 30일)
이전 댓글 표시
I have a contour plot. I want to change only the background color not the contour color. Can you please suggest me how can I do that?
댓글 수: 0
답변 (1개)
Abhishek
2025년 3월 7일
Hi,
In order to change the background colour of a contour plot, without affecting the contour colours, you can use the "set" function. The “set” function is used to change the “Color” property of the current axes. This changes the background colour of the plot area without affecting the contour lines.
For more details, you can refer to the below MATLAB documentation on “set” function: https://www.mathworks.com/help/releases/R2024b/matlab/ref/set.html
The following sample code will display a contour plot with a light blue background.
[X, Y] = meshgrid(-5:0.1:5, -5:0.1:5);
Z = sin(sqrt(X.^2 + Y.^2));
contour(X, Y, Z);
% Adjust the RGB values in the set function to
% change the background to any color you prefer.
set(gca, 'Color', [0.8, 0.9, 1.0]);
title('Light Blue Background');
I have attached the plot for both blue as well as green background plots. Hope this solves the issue.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Contour Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!