Bar plot with a hatched fill pattern
I have a grouped bar plot, bb:
bb = bar(ax, x, y)
where ‘ax’ is the axis handle, x is a 1×7 datetime vector and y is a 5×7 double vector. For each of the seven dates, I get five bars with data.
I then specify the color of the bars:
for i = 1:5
bb(i).FaceColor = colmapLight(i,:);
bb(i).EdgeColor = colmapDark(i,:);
end
In addition to specifying the colors, I want to use a hatched fill pattern, e.g. horizontal lines in the first two bars in each group, and dots in the last three. I tried using the functions mentioned in this post (https://blogs.mathworks.com/pick/2011/07/15/creating-hatched-patches/), but I haven’t managed to make any of them work. I think the hatchfill function (https://se.mathworks.com/matlabcentral/fileexchange/30733-hatchfill) suits my needs best (I want to keep my custom bar colors; plus I don’t need a bitmap copy of the figure, want to keep it as a fig). However, the function works on ‘patch’ objects and I don’t know how to get their handles. The following:
hPatch = findobj(bb, ‘Type’, ‘patch’);
returns an empty, 0x0 GraphicsPlaceholder.
Does anyone know a way to solve this? Thanks in advance!I have a grouped bar plot, bb:
bb = bar(ax, x, y)
where ‘ax’ is the axis handle, x is a 1×7 datetime vector and y is a 5×7 double vector. For each of the seven dates, I get five bars with data.
I then specify the color of the bars:
for i = 1:5
bb(i).FaceColor = colmapLight(i,:);
bb(i).EdgeColor = colmapDark(i,:);
end
In addition to specifying the colors, I want to use a hatched fill pattern, e.g. horizontal lines in the first two bars in each group, and dots in the last three. I tried using the functions mentioned in this post (https://blogs.mathworks.com/pick/2011/07/15/creating-hatched-patches/), but I haven’t managed to make any of them work. I think the hatchfill function (https://se.mathworks.com/matlabcentral/fileexchange/30733-hatchfill) suits my needs best (I want to keep my custom bar colors; plus I don’t need a bitmap copy of the figure, want to keep it as a fig). However, the function works on ‘patch’ objects and I don’t know how to get their handles. The following:
hPatch = findobj(bb, ‘Type’, ‘patch’);
returns an empty, 0x0 GraphicsPlaceholder.
Does anyone know a way to solve this? Thanks in advance! I have a grouped bar plot, bb:
bb = bar(ax, x, y)
where ‘ax’ is the axis handle, x is a 1×7 datetime vector and y is a 5×7 double vector. For each of the seven dates, I get five bars with data.
I then specify the color of the bars:
for i = 1:5
bb(i).FaceColor = colmapLight(i,:);
bb(i).EdgeColor = colmapDark(i,:);
end
In addition to specifying the colors, I want to use a hatched fill pattern, e.g. horizontal lines in the first two bars in each group, and dots in the last three. I tried using the functions mentioned in this post (https://blogs.mathworks.com/pick/2011/07/15/creating-hatched-patches/), but I haven’t managed to make any of them work. I think the hatchfill function (https://se.mathworks.com/matlabcentral/fileexchange/30733-hatchfill) suits my needs best (I want to keep my custom bar colors; plus I don’t need a bitmap copy of the figure, want to keep it as a fig). However, the function works on ‘patch’ objects and I don’t know how to get their handles. The following:
hPatch = findobj(bb, ‘Type’, ‘patch’);
returns an empty, 0x0 GraphicsPlaceholder.
Does anyone know a way to solve this? Thanks in advance! bar, plot, patch, hatched, pattern MATLAB Answers — New Questions