1

enter image description here

I would like to have the text like '(a)' in the position outside the plot next to the x-ticks in a Tikzpicture. I tried saving the plot generated by matplotlib in tikz format, and use that in Latex file. However the text disappears when it is outside the plot

The tikzpicture file which I saved from Matplotlib is given by :

\begin{tikzpicture}

\definecolor{color0}{rgb}{0.12156862745098,0.466666666666667,0.705882352941177}
\definecolor{color1}{rgb}{1,0.498039215686275,0.0549019607843137}

\begin{axis}[
height=\figH,
tick align=outside,
tick pos=left,
width=\figW,
x grid style={white!69.0196078431373!black},
xmajorgrids,
xmin=-4.44444444444444e-05, xmax=0.000933333333333333,
xtick style={color=black},
y grid style={white!69.0196078431373!black},
ymajorgrids,
ymin=0.125777210945621, ymax=0.82064477120417,
ytick style={color=black}
]
\addplot [semithick, color0]
table {%
0 0.157362100048282
0.000222222222222222 0.231964290056153
0.000444444444444444 0.789059882101509
0.000666666666666667 0.661985011331508
0.000888888888888889 0.176917594785121
};
\addplot [semithick, color1, mark=asterisk, mark size=3, mark options={solid}, only marks]
table {%
0 0.309631433514708
0.000222222222222222 0.356544604589611
0.000444444444444444 0.403457775664515
0.000666666666666667 0.450370946739418
0.000888888888888889 0.497284117814321
};
\end{axis}

\draw ({$(current bounding box.south west)!0.02!(current bounding box.south east)$}|-{$(current bounding box.south west)!0.9!(current bounding box.north west)$}) node[
  scale=0.7,
  anchor=base west,
  text=black,
  rotate=0.0
]{(a)};
\end{tikzpicture}```
6
  • 1
    Please. Gives a MWE...
    – projetmbc
    Apr 21, 2021 at 13:34
  • 2
    Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    – Rmano
    Apr 21, 2021 at 13:39
  • 1
    What is meaning of (a)? If this is sub-caption label, than write it as part of sub-figure environment, as is done in tex.stackexchange.com/questions/20354, if not, add it to image as ylabel accordingly positioned.
    – Zarko
    Apr 21, 2021 at 14:02
  • @Zarko ! Thank you for your suggestion with sub-figure environment. I have tried it. However it takes up horizontal space.
    – Rakesh
    Apr 21, 2021 at 14:17
  • @Zarko! The '(a)' is just to name the figures since they are presented in a 4x2 array format. I would like to have '(a)' till '(e)', and place them in line with the x-ticks. Could you tell me how to achieve this ?
    – Rakesh
    Apr 21, 2021 at 14:21

2 Answers 2

1

Edit: Slightly improved images styles and positioning of pictures layout.

If I understood your question and comments to it correctly, than you after for something like this:

enter image description here

(red lines indicate page layout)

Above image is produced by:

\RequirePackage{filecontents}
    \begin{filecontents}{data.dat}
x                    y1                y2
0                    0.157362100048282 0.309631433514708
0.000222222222222222 0.231964290056153 0.356544604589611
0.000444444444444444 0.789059882101509 0.403457775664515
0.000666666666666667 0.661985011331508 0.450370946739418
0.000888888888888889 0.176917594785121 0.497284117814321
    \end{filecontents}

\documentclass{article}
\usepackage{pgfplots}
    \pgfplotsset{compat=1.17}
\usepackage{floatrow}
\usepackage{graphicx}
\usepackage[font=footnotesize, label font=bf]{subfig}
\usepackage{caption}
\floatsetup[figure]{style=plain,capbesidewidth=-1em,
                    subcapbesideposition=bottom}

%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}% For dummy text. Don't use in a real document


\begin{document}    
\begin{figure}[!ht]
\pgfplotsset{
    width=0.4\linewidth, height=0.2\textheight,
    scale only axis,
    tick align=outside, tick pos=left,
        tick style = {semithick, tickwidth=1mm}, % added
    grid,
    grid style={very thin, gray!30},
    enlarge x limits =0.04,
    xmin=0, xmax=0.0009,
    xtick={0,0.0002,...,0.0008},
    scaled x ticks=false,
    xticklabel style={/pgf/number format/.cd,
            fixed, precision=4},
    ymin=0, ymax=0.95,
    ytick={0,0.1,...,0.9},
    tick label style={font=\scriptsize, inner xsep=1pt}
        }
        
\sidesubfloat[]{\hspace{-1em}%
    \begin{tikzpicture}
\begin{axis}            ]
\addplot +[semithick] table [y=y1]{data.dat};
\addplot +[semithick,
           mark=asterisk, only marks] table [y=y2]{data.dat};
\end{axis}
    \end{tikzpicture}
}\hfill
\sidesubfloat[]{\hspace{-1em}%
    \begin{tikzpicture}
\begin{axis}            ]
\addplot +[semithick] table [y=y1]{data.dat};
\addplot +[semithick,
           mark=asterisk, only marks] table [y=y2]{data.dat};
\end{axis}
    \end{tikzpicture}
}

\medskip
\sidesubfloat[]{\hspace{-1em}%
    \begin{tikzpicture}
\begin{axis}            ]
\addplot +[semithick] table [y=y1]{data.dat};
\addplot +[semithick,
           mark=asterisk, only marks] table [y=y2]{data.dat};
\end{axis}
    \end{tikzpicture}
}\hfill
\sidesubfloat[]{\hspace{-1em}%
    \begin{tikzpicture}
\begin{axis}
\addplot +[semithick] table [y=y1]{data.dat};
\addplot +[semithick,
           mark=asterisk, only marks] table [y=y2]{data.dat};
\end{axis}
    \end{tikzpicture}
}

\medskip
\sidesubfloat[]{\hspace{-1em}%
    \begin{tikzpicture}
\begin{axis}            ]
\addplot +[semithick] table [y=y1]{data.dat};
\addplot +[semithick,
           mark=asterisk, only marks] table [y=y2]{data.dat};
\end{axis}
    \end{tikzpicture}
}\hfill
\sidesubfloat[]{\hspace{-1em}%
    \begin{tikzpicture}
\begin{axis}
\addplot +[semithick] table [y=y1]{data.dat};
\addplot +[semithick,
           mark=asterisk, only marks] table [y=y2]{data.dat};
\end{axis}
    \end{tikzpicture}
}

\medskip
\sidesubfloat[]{\hspace{-0.75em}%
    \begin{tikzpicture}
\begin{axis}            ]
\addplot +[semithick] table [y=y1]{data.dat};
\addplot +[semithick,
           mark=asterisk, only marks] table [y=y2]{data.dat};
\end{axis}
    \end{tikzpicture}
}\hfill
\sidesubfloat[]{\hspace{-0.75em}%
    \begin{tikzpicture}
\begin{axis}
\addplot +[semithick] table [y=y1]{data.dat};
\addplot +[semithick,
           mark=asterisk, only marks] table [y=y2]{data.dat};
\end{axis}
    \end{tikzpicture}
}
    \caption{Image}
    \label{fig.sicaptions}
\end{figure}
    \end{document}

Of course, you need insert correct image code to each \sidesubfloat. Hopefully they all have the same settings.

2
  • +1 for solution, but looking at e.g. (c), I can not see if the belonging graph is above or below. (I realise that you are not the one wishing to do it like this). Apr 21, 2021 at 18:57
  • 1
    @hpekristiansen, sorry, I do not understand your comment. I only show possibilities how to add caption labels to OP images. I didn't express any my preferences about positioning of caption labels. Now are (more or les) in line with xtick labels, as OP request in his/her comment. Separation between rows with images can be increased by replacing \medskip with \bigskip or with \vspace{<desired distance>}.
    – Zarko
    Apr 21, 2021 at 20:27
0

Let's see: if you want to move your "(a)" label where you want, I'd do:

  1. be sure to use a \pgfplotsset{compat=1.15} or higher (we don't know because your snippet is not complete);
  2. add to the options clip mode=individual, so that nodes or lines that you add are not clipped out;
  3. add the \node inside the axis environment. If you use the rel axis cs: coordinate system, you can use a 0,0 as the bottom left and (1,1) as the top right. Add the option you want to the node; I put mine here at (0,1) (top left), aligned above left with no separation and filling its background white.
\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}\pgfplotsset{compat=1.16}% > 1.11!!!
\begin{document}
\begin{tikzpicture}[]
   \definecolor{color0}{rgb}{0.12156862745098,0.466666666666667,0.705882352941177}
\definecolor{color1}{rgb}{1,0.498039215686275,0.0549019607843137}

\begin{axis}[
tick align=outside,
tick pos=left,
x grid style={white!69.0196078431373!black},
xmajorgrids,
xmin=-4.44444444444444e-05, xmax=0.000933333333333333,
xtick style={color=black},
y grid style={white!69.0196078431373!black},
ymajorgrids,
ymin=0.125777210945621, ymax=0.82064477120417,
ytick style={color=black},
%%% added
clip mode=individual
%%%
]
\addplot [semithick, color0]
table {%
0 0.157362100048282
0.000222222222222222 0.231964290056153
0.000444444444444444 0.789059882101509
0.000666666666666667 0.661985011331508
0.000888888888888889 0.176917594785121
};
\addplot [semithick, color1, mark=asterisk, mark size=3, mark options={solid}, only marks]
table {%
0 0.309631433514708
0.000222222222222222 0.356544604589611
0.000444444444444444 0.403457775664515
0.000666666666666667 0.450370946739418
0.000888888888888889 0.497284117814321
};
%%%
%%%added
\node[fill=white, inner sep=0pt, above left] at (rel axis cs:0,1) {\textbf{(a)}}; 
\end{axis}

\end{tikzpicture}
\end{document}

enter image description here

PS: notice that this is a correct minimal working example (MWE)

1
  • 1
    You can also use \path (rel axis cs:0,1) coordinate (aux); \end{axis} \node[fill=white, inner sep=0pt, above left] {\textbf{(a)}} at (aux);, then there is not need to change the clipping, which is sometimes needed to produce the plot one wants.
    – user240002
    Apr 21, 2021 at 18:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .