change only the background color of contour plot

7 visualizzazioni (ultimi 30 giorni)
TUHIN
TUHIN il 29 Apr 2016
Risposto: Abhishek il 7 Mar 2025
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?

Risposte (1)

Abhishek
Abhishek il 7 Mar 2025
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.

Categorie

Scopri di più su Contour Plots in Help Center e File Exchange

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by