Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to put a pgfplots plot beside several other pdf images that I import into my document, but I can't figure out how to position the pgfplots axis in the larger tikzpicture:

\documentclass{article}

\usepackage{graphicx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}

\begin{document}
\begin{figure*}

  \begin{center}
    \begin{tikzpicture}

       \node[anchor=south west] (img) at (0,0) 
            {\includegraphics[width=0.3\linewidth]{1.pdf}};
       \node[anchor=south west] 
            at (0.01\linewidth,0.01\linewidth) {a};        

       \node[anchor=south west] (img) at (0.33\linewidth,0) 
            {\includegraphics[width=0.3\linewidth]{1.pdf}};
       \node[anchor=south west] 
            at (0.34\linewidth,0.01\linewidth) {b}; 

       \begin{axis}[width=0.45\linewidth, yticklabels={}]
         \addplot [const plot, fill=red] 
                  table [x index=0, y index=1]
                  {hist.txt}
         \closedcycle;  
       \end{axis}

    \end{tikzpicture}
  \end{center}

  \caption{\label{detdemo}An example of my output}
\end{figure*}
\end{document}

here is the example output: example output

The axis seems to begin from the (0,0) of the tikzpicture.

I wanted to see how I can position this axis after the second picture? Such that its bottom left corner is on (0.66\linewidth,0).

share|improve this question
    
You want the plot to come after the second picture? –  Harish Kumar Mar 24 at 10:44
    
Yes, I want the bottom left point of the plot to be on (0.66\linewidth,0). –  makhlaghi Mar 24 at 10:46

3 Answers 3

up vote 5 down vote accepted

You can define the coordinate for the lower left corner of the axis with the at key,

at={(0.66\linewidth,0)}

Add this to the axis options.

enter image description here

\documentclass{article}

\usepackage{graphicx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}

\begin{document}
\begin{figure*}

  \begin{center}
    \begin{tikzpicture}

       \node[anchor=south west] (img) at (0,0) 
            {\includegraphics[width=0.3\linewidth]{example-image-a}};
       \node[anchor=south west] 
            at (0.01\linewidth,0.01\linewidth) {a};        

       \node[anchor=south west] (img) at (0.33\linewidth,0) 
            {\includegraphics[width=0.3\linewidth]{example-image-b}};
       \node[anchor=south west] 
            at (0.34\linewidth,0.01\linewidth) {b}; 

       \begin{axis}[width=0.45\linewidth, yticklabels={},at={(0.66\linewidth,0)}]
         \addplot [const plot, fill=red] 
                  {x}
         \closedcycle;  
       \end{axis}

    \end{tikzpicture}
  \end{center}

  \caption{\label{detdemo}An example of my output}
\end{figure*}
\end{document}
share|improve this answer
    
very simple and nice solution. Thank you very much. –  makhlaghi Mar 24 at 11:14

As a quick hack, you can either use a scope with a proper xshift or put the axis inside another node.

\documentclass{article}

\usepackage{graphicx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\usetikzlibrary{positioning}

\begin{document}
\begin{figure*}

  \begin{center}
    \begin{tikzpicture}

       \node[anchor=south west] (img1) at (0,0)
            {\includegraphics[width=0.3\linewidth]{example-image-a}};
       \node[anchor=south west]
            at (0.01\linewidth,0.01\linewidth) {a};

       \node[anchor=south west] (img2) at (0.33\linewidth,0)
            {\includegraphics[width=0.3\linewidth]{example-image-b}};
       \node[anchor=south west]
            at (0.34\linewidth,0.01\linewidth) {b};
       \begin{scope}[xshift=0.66\linewidth] 
       \begin{axis}[width=0.45\linewidth, yticklabels={}]
         \addplot [const plot, fill=red]
                  {x}       %% I changed this change it back
         \closedcycle;
       \end{axis}
       \end{scope}

    \end{tikzpicture}
  \end{center}

  \caption{\label{detdemo}An example of my output comes here}
\end{figure*}
\end{document}

enter image description here

But it will be better if you use another tikzpicture environment IMO.

share|improve this answer
    
See my answer ... –  Torbjørn T. Mar 24 at 11:08
1  
@TorbjørnT. Technically both do the same :) Yours is more pgfplots way though. –  Harish Kumar Mar 24 at 11:15
1  
Yeah, I suppose so. –  Torbjørn T. Mar 24 at 11:27

I did not read your question carefully, but...

The correct way of adding axis to an existing graphics in PGFPlots is:

\begin{axis}
  \addplot graphics[xmin=0,xmax=1,ymin=0,ymax=1] {image.jpg};
\end{axis}

If you want to group plots in PGFPlots, use the groupplots library.

share|improve this answer
2  
If you do read it carefully, you may find that this doesn't really answer the question. –  Torbjørn T. Mar 24 at 11:04
    
Also a note, what is done in that snippet is not "adding axis to an existing graphics", but the opposite - adding graphics (image) to an axis (plot). –  sdaau Jun 25 at 14:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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