Background color of part of figure

17 views (last 30 days)
IBRAHIM BOZTAS
IBRAHIM BOZTAS on 10 Dec 2020
Commented: IBRAHIM BOZTAS on 10 Dec 2020
%Objective Function --> 8*X1 + 10*X2 + 4
%Constrait 1 --> X1 - X2 >= -4
%Constrait 2 --> X1 + X2 <= 6
%Boundary Conditions --> X1,X2 >= 0
%%
%Graphical Method
X1=-5:5;
X2=-5:5;
[x,y]=meshgrid(X1,X2);
z=8*x+10*y+4;
figure
contour(x,y,z);
[C,h]=contour(x,y,z,17);hold on;
clabel(C,h);
plot(X1,X2-4,'r');hold on;
plot(X1,6-X2,'b');hold on;
plot(X1,zeros(1,length(X2)),'k');hold on;
plot(zeros(1,length(X1)),X2,'k');
axis([-5 5 -5 5])
Hi everyone
I want to change the background color of part of the graph is shown above. The part of the graph is between four lines, that are x>0,y>0 , x-y>-4 and x+y<6. If you could help me I would be very grateful.

Answers (1)

Image Analyst
Image Analyst on 10 Dec 2020
Add this:
% Make the background yellow.
ax = gca
ax.Color = 'y';
Alternatively you can specify an RGB color in the range 0-1, like for cyan:
% Make the background yellow.
ax = gca
ax.Color = [0, 1, 1];
  1 Comment
IBRAHIM BOZTAS
IBRAHIM BOZTAS on 10 Dec 2020
Thank you but it makes the background of the whole graph yellow. I just want to change the background color of part of the graph.

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!