TeX - LaTeX Asked by A. Donda on February 11, 2021
In this TikZ picture
begin{tikzpicture}
draw (0,0) rectangle (5,5);
draw[color=blue] plot[mark=*] coordinates {(-2,3) (0,1) (2,3) (4,2) (6,4)};
end{tikzpicture}
I would like to clip the blue plot lines to the black rectangle. Of course I can achieve that by adding the clip
option to the first draw
command:
begin{tikzpicture}
draw[clip] (0,0) rectangle (5,5);
draw[color=blue] plot[mark=*] coordinates {(-2,3) (0,1) (2,3) (4,2) (6,4)};
end{tikzpicture}
However, that leads to the plot mark at the edge to be cut in half. Instead, I would like a plot mark to be clipped (not displayed) either completely if the coordinate lies outside of the clip region, or displayed completely if the coordinate lies inside. The result would be like this:
Is it possible to achieve that with some TikZ trickery (i.e. apart from plotting the lines and marks separately)?
As shown here, you need to add clip marker paths=true
to the options. Additionally, you may want to use axis on top
.
documentclass{standalone}
usepackage{pgfplots}
begin{document}
begin{tikzpicture}
begin{axis}[
xmin=0,xmax=5,
ymin=0,ymax=5,
axis equal image, axis on top,
clip marker paths=true, ticks=none]
addplot+[color=blue,mark=*]
coordinates {(-2,3) (0,1) (2,3) (4,2) (6,4)};
end{axis}
end{tikzpicture}
end{document}
Answered by manooooh on February 11, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP