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 nofacecolorproperty onaxesclass.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
Post a Comment