Is it possible to create interconnected graphs in pgfplots (e.g. common grids), like the picture below?

And, related to the question above, if you have one tikzpicture environment with two axis environments, is it possible to ensure, that both will have exactly the same measure on both x and y axis?

enter image description here

Edit: I tried to write x axis grid manually, but I had problems using foreach. E.g. example below simply does not work (bunch of endcsname errors).


\addplot {cos(x)};
\foreach \i in {180,360,540} {\node (a\i) at (axis cs:\i,0) {};}


Concerning the first question (grids which pass through a couple of vertically adjacent axes): this will only work if you move the axes so close to each other that the independent grids touch each other (which means that the drawn axis lines will also touch each other). pgfplots has no builtin solution for this feature.

Concerning the second question (ensure the same unit scales): yes, you can explicitly set the amount of space used for each unit (using x=1cm,y=2cm or something like that, compare the manual), and you can explicitly set the displayed ranges (xmin=0,xmax=5).

  • Concerning the first question, since there is no interest for such addition as far as voting is concerned, would it be possible to create vertical grids manually? E.g. would it be possible to e.g. connect point (cs:2,2) of the first graph to the point (cs:2,-2) of the last graph? – Pygmalion Aug 25 '12 at 12:54
  • yes, I would say so. You would probably need some sort of loop to introduce labelled coordinates inside of the first axis and then, after the last axis, you could probably generate TikZ drawing instructions. Interesting aspects might be \pgfkeysvalueof{/pgfplots/ymax} which expands to the maximum y axis limit (but only inside of an axis) and \draw[/pgfplots/every axis grid] which uses the standard grid style of pgfplots. – Christian Feuersänger Aug 25 '12 at 13:10
  • I succeeded to create it, using your advices. – Pygmalion Aug 27 '12 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.