Fill a specific area of the plot with Diagonal Lines, or Vertical Lines

Hello,
My objective is to produce within a range, diagonal lines or horizontal lines instead of just filling the all space with a colour, as you can see in the image I have attached.
x = 1:100;
f = sin(x);
x1 = [20 35 35 20]
y1 = [0.4 0.4 0.7 0.7]
plot(x,f);
patch(x1,y1,'b')

8 Commenti

Like a hatched patch (link)? There is, to my knowledge, no built-in matlab function for this.
Would an alternative be to make the box transparent?
I would like my blue box, instead of filling a solid blue be filled like the Banana box or the Bana box that link shows.
The goal is to catch the attention of the persons who are seeing the plot for that area, and that's why I thought about diagonal lines within a rectangle that is the box blue but with diagonal lines instead of the blue solid
I have two alternatives, one is to change the facealpha property of your patch, to make it transparent.
x = 1:100;
f = sin(x);
x1 = [20 35 35 20]
y1 = [0.4 0.4 0.7 0.7]
h=plot(x,f);
p=patch(x1,y1,'b');
set(p,'facealpha','0.1')
the other one is to follow the example given in the blogpost. It's quite straight-forward but you need to download the custom function hatchfill (link)
The function hatchill or even the example I cant make it work
1. Download hatchfillpkg.zip
2. Extract folder and add to matlab search path
3. type 'help hatchfill' to make sure you have completed steps 1-2 (some documentation should show)
type following code:
x = 1:100;
f = sin(x);
x1 = [20 35 35 20]
y1 = [0.4 0.4 0.7 0.7]
h=plot(x,f);
p=patch(x1,y1,'b');
hatchfill(p);
This should give you the attached result
yes it does, by any chance can i place the color of the lanes? or it is done to be always black?
Great, a general tip for matlab is to save the handle of your object (axes, line, figure etc..). For example,
hf = hatchfill(p);
You can then easily type get(hf) to get a list of all its properties, including the color, which you can then alter.
set(hf,'color',[1 0 0]) %sets line color to red
oh ok, i was trying somrthing like hatchill.Color = 'red' but wasnt going anywhere xD thanks mate

Accedi per commentare.

Risposte (0)

Richiesto:

il 27 Apr 2018

Commentato:

il 27 Apr 2018

Community Treasure Hunt

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

Start Hunting!

Translated by