![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/306339/image.png)
Place grid on top of patches
117 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Niccolò Moro
le 30 Mai 2020
Commenté : Star Strider
le 5 Juil 2022
Hi everybody,
I want to place a grid (only y-axis) on top of my graph which is covered by patches. The patches are 15% transparent, therefor the grid can already bee seen slightly. However, it would be way better to see the whole grid. Does anyone have an input how to achieve this?
At the moment i call the grid like this:
set(gca, 'XGrid', 'on', 'YGrid', 'off');
This is the current state of the graph:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/306259/image.png)
Thank you for your input.
0 commentaires
Réponse acceptée
Star Strider
le 30 Mai 2020
Modifié(e) : Star Strider
le 30 Mai 2020
The gridlines can be put on top of the figure, and you can also vary the transparency of the grid lines.
Example —
x = 1:10;
y = rand(2, 10);
figure
subplot(2,1,1)
patch([x fliplr(x)], [y(1,:) fliplr(y(2,:))+1], 'r', 'FaceAlpha', 0.3)
Ax = gca;
Ax.YGrid = 'on';
Ax.GridAlpha = 0.5;
subplot(2,1,2)
patch([x fliplr(x)], [y(1,:) fliplr(y(2,:))+1], 'r', 'FaceAlpha', 0.3)
Ax = gca;
Ax.YGrid = 'on';
Ax.Layer = 'top';
Ax.GridAlpha = 0.5;
EDIT —
Added plot image
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/306339/image.png)
.
5 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!