2

I'm trying to zoom in a tikzpicture with the Spy library but I would like the shape of the magnifier to be given by a path (for example, a hexagon shape). Is it possible? And is it possible to show only the zoomed portion?

Here is a MWE taken for the pgfmanual:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{pgfplots} \pgfplotsset{compat=newest} \usepackage{tikz} \usetikzlibrary {decorations.fractals,spy}

\begin{document} \begin{tikzpicture}[spy using overlays={size=12mm}] \draw [decoration=Koch snowflake] decorate { decorate{ decorate{ decorate{ (0,0) -- (2,0) }}}}; \spy [blue,magnification=5] on (1,0.5) in node at (1,-1); \end{tikzpicture} \end{document}

Pedro
  • 474
  • 2
  • 10

1 Answers1

2

You can use the polygon node shape from the TikZ shapes library like this:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{pgfplots} \pgfplotsset{compat=newest} \usepackage{tikz} \usetikzlibrary {decorations.fractals,spy, shapes}

\begin{document} \begin{tikzpicture}[regular polygon, regular polygon sides=6, spy using overlays={size=12mm}] \draw [decoration=Koch snowflake] decorate { decorate{ decorate{ decorate{ (0,0) -- (2,0) }}}}; \spy [blue,magnification=5] on (1,0.5) in node at (1,-1); \end{tikzpicture} \end{document}

Hexagon spy shape

  • Thanks but how can a path be explicitly defined? Like e.g. \path (1,1)--(0.5,0.5)--(1.5,0.5)--cycle – Pedro Jun 25 '20 at 16:16
  • And how can the magnified part be the only part showing (hidding the original picture)? – Pedro Jun 25 '20 at 16:50
  • 1
    For a custom node shape see: https://tex.stackexchange.com/questions/294876/pgf-tikz-node-custom-shape. If you do not want the original picture, then why draw it and then use spy - just draw only the large version. To help you further, you need to edit your question, and include a picture of what you seek and describe what is causing you problems. – hpekristiansen Jun 25 '20 at 20:59
  • The problem is the \clip is not working here: https://tex.stackexchange.com/questions/550140/zoom-in-a-tikz-mindmap. That is why I am trying with \spy that works. – Pedro Jun 25 '20 at 21:13
  • I fail to understand how clip fails to clip. I do not think you need or want spy for this purpose. Include a picture of what you seek and describe what is causing you problems. – hpekristiansen Jun 25 '20 at 21:56
  • everything is explained in the link above with images and code. The \clip (in the beginning of the code) clips but some path joints are not clipped. Strange behaviour. But executing \spy at the end of the code works perfectly. Can you please take a look at the link with my mindmap question? – Pedro Jun 26 '20 at 07:00