How to correctly adjust the FaceColor property of patch objects in a figure with a legend?
Hello community,
I am having an issue adjusting the FaceColor property of patch objects in a figure. That is, only the legend is updated when I try to change the color of a patch object. My issue can be replicated with the code below:
% Load the figure
openfig(‘cylinder.fig’);
The figure contains four patch objects combined to form a cylindrical shape. The figure also contains a legend.
When I save the patch objects to the variable patches I do not receive any errors:
% Get all patch objects in the figure
patches = findobj(gcf,’Type’,’patch’);
disp([‘The number of patch objects is ‘ num2str(length(patches)) ‘.’])
However, when I try to change the face color of one of the patch objects, the color is only changed inside of the legend. For example,
patches(1).FaceColor = ‘r’;
results in the following visual change:
My best guess is that the findobj() function is only identifying the patch objects in the legend and not the objects composing the cylinder, but I am not sure how to confirm this.
My question: Am I making a programmatic mistake? Or is there a bug in how MATLAB is applying the color change operation to the patch object? Thank you in advance for the help!
P.S. I am using MATLAB Online for my problem, in case that makes a difference.Hello community,
I am having an issue adjusting the FaceColor property of patch objects in a figure. That is, only the legend is updated when I try to change the color of a patch object. My issue can be replicated with the code below:
% Load the figure
openfig(‘cylinder.fig’);
The figure contains four patch objects combined to form a cylindrical shape. The figure also contains a legend.
When I save the patch objects to the variable patches I do not receive any errors:
% Get all patch objects in the figure
patches = findobj(gcf,’Type’,’patch’);
disp([‘The number of patch objects is ‘ num2str(length(patches)) ‘.’])
However, when I try to change the face color of one of the patch objects, the color is only changed inside of the legend. For example,
patches(1).FaceColor = ‘r’;
results in the following visual change:
My best guess is that the findobj() function is only identifying the patch objects in the legend and not the objects composing the cylinder, but I am not sure how to confirm this.
My question: Am I making a programmatic mistake? Or is there a bug in how MATLAB is applying the color change operation to the patch object? Thank you in advance for the help!
P.S. I am using MATLAB Online for my problem, in case that makes a difference. Hello community,
I am having an issue adjusting the FaceColor property of patch objects in a figure. That is, only the legend is updated when I try to change the color of a patch object. My issue can be replicated with the code below:
% Load the figure
openfig(‘cylinder.fig’);
The figure contains four patch objects combined to form a cylindrical shape. The figure also contains a legend.
When I save the patch objects to the variable patches I do not receive any errors:
% Get all patch objects in the figure
patches = findobj(gcf,’Type’,’patch’);
disp([‘The number of patch objects is ‘ num2str(length(patches)) ‘.’])
However, when I try to change the face color of one of the patch objects, the color is only changed inside of the legend. For example,
patches(1).FaceColor = ‘r’;
results in the following visual change:
My best guess is that the findobj() function is only identifying the patch objects in the legend and not the objects composing the cylinder, but I am not sure how to confirm this.
My question: Am I making a programmatic mistake? Or is there a bug in how MATLAB is applying the color change operation to the patch object? Thank you in advance for the help!
P.S. I am using MATLAB Online for my problem, in case that makes a difference. plotting MATLAB Answers — New Questions