Is there a way to get a line/ patch object from a bar plot, if there even is such object in a bar plot?
I'm trying to implement "hatch" (https://se.mathworks.com/matlabcentral/fileexchange/2075-hatch-m) together with "bar" but can't extract the expected object, not even:
findobj(b(1), 'Type', 'patch')
works...
Is it simply so that bar does not contain what I search for and I have to forfit my attempts at "hatching" the bars?

 Respuesta aceptada

Mario Malic
Mario Malic el 5 de Nov. de 2020

0 votos

It looks like such object does not exist on bar anymore.

5 comentarios

Kristoffer Clasén
Kristoffer Clasén el 5 de Nov. de 2020
Of course it doesn't exist anymore, excellent... So hatch won't work on bar then.
I've tried "applyhatch_pluscolor" as well, but with disappointing result. Anyone that happens to have a suggestion on how to plot hatch/ patterns on barplots without spending days on new code? I've red the blog post by Jiro and searched but no luck so far.
Mario Malic
Mario Malic el 5 de Nov. de 2020
Editada: Mario Malic el 5 de Nov. de 2020
You can actually use patch function.
x = 1900:10:2000;
y = [75 91 105 123.5 131 150 179 203 226 249 281.5];
Bar_Obj = bar(x,y);
% Get data about bars
x_points = Bar_Obj.XEndPoints;
y_points = Bar_Obj.YEndPoints;
width = abs(x(1)-x(2))*Bar_Obj.BarWidth/2; % BarWidth is relative measure
From this, you can construct each polygon,
Poly_X = [x_points-width; x_points+width; x_points+width; x_points-width]; % x coords counter clockwise, 1st point is down-left
Poly_Y = [zeros(size(x_points)); zeros(size(x_points)); y_points; y_points]; % y coords ccw
c = repmat([0 6 4 2]', [1,length(y_points)]); % color, find example in patch
And finally,
patch (Poly_X, Poly_Y, c);
Probably, you can reuse the same idea with function imagesc if you'd provide hatch images.
Kristoffer Clasén
Kristoffer Clasén el 6 de Nov. de 2020
Aaaand it seems I don't have EndPoints in my release either, but perhaps it works with YData/XData instead.
I also realize a problem in that I have errorbars as well so I assume I have to chop up the errorbarbar function and plot the errorbars after patching/ hatching to not cover them.
Thanks Mario
Mario Malic
Mario Malic el 6 de Nov. de 2020
It should properly work with mentioned properties and yes, errorbar comes after patching.
You're welcome.
Kristoffer Clasén
Kristoffer Clasén el 6 de Nov. de 2020
Editada: Kristoffer Clasén el 6 de Nov. de 2020
I just found hatchfill2 which appears to accept bar as object input, and I also found a thread with an example of how to "hatch" the legend which also was a concern:
So I'll most likely continue with this option

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Object Properties en Centro de ayuda y File Exchange.

Productos

Versión

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by