bar chart - Change color of bar graph after reopen figure file in MATLAB -


i have lot of graphs fig file , want change font size , color of these in function. in example, it's bar graph.

this code:

function changeproperties(fontsize, figdata)    openfig(figdata);    set(gca,'fontsize',fontsize);    set(gca,'facecolor','r');    saveas(gcf,'graph.pdf','pdf'); end 

it changes fontsize, not bar color.

the error message this:

error using matlab.graphics.axis.axes/set
there no facecolor property on axes class.

error in changeallfonts (line 4)
‍‍‍‍‍‍ ‍‍‍‍‍‍ set(gca,'facecolor','r');

gcf doesn't work. fault?

you open saved .fig files, need right handle bar object (children of axes) posteriorly (i.e. after exists, , not while creating it). quite robust way use findobj:

function changeproperties(fontsize,figdata)    openfig(figdata);    set(gca,'fontsize',fontsize);    b = findobj(gca,'type','bar'); % returns handle bar    set(b,'facecolor','r'); % changes bars in current axes    saveas(gcf,'graph.pdf','pdf'); end 

this way, if axes include other objects, won't affected.

also, if use function open multiple figures, might want add close command (close(gcf)), otherwise it's harder guarantee current axes indeed want change.


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -