Fill a specific area of the plot with Diagonal Lines, or Vertical Lines
Mostra commenti meno recenti
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
jonas
il 27 Apr 2018
Would an alternative be to make the box transparent?
Tiago Dias
il 27 Apr 2018
Modificato: Tiago Dias
il 27 Apr 2018
jonas
il 27 Apr 2018
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)
Tiago Dias
il 27 Apr 2018
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
Tiago Dias
il 27 Apr 2018
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
Tiago Dias
il 27 Apr 2018
Risposte (0)
Categorie
Scopri di più su Axis Labels in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!