0

I'm dealing with a bunch of plots and groupplots, and sometimes something weird happens. I'm plotting from data tables and when it comes to decide the y tick distance, sometimes the scientific notation is "well placed" (at least for my personal needs), sometimes not. Here two images:

enter image description here

The first image as you can see, put the 10^-2 right on the top, while the second one represents the "issue" I would like to point out. Is there a way to force the scientific notation to stay on the top of the graph? I don't get how the algorithm decide to place the notation.

Here the groupplot structure I'm currently using:

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{pgf,pgfplots,pgfplotstable}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{colormaps}
\usepgfplotslibrary{groupplots}

\begin{document}


\begin{figure}[htbp]
    \centering
    \pgfplotstableread{data/v3/b1/vel/vzt.dat}{\DataTableA}
    \pgfplotstableread{data/v3/b2/vel/vzt.dat}{\DataTableB}
 
    \begin{tikzpicture}[scale=0.9]
        \begin{groupplot}[group style={
        group name=vztcompcross,
        group size=1 by 2,
        xlabels at=edge bottom,
        ylabels at=edge left,
        vertical sep=4em
        },
        xmin = 0, xmax = 30,
        ymin = -0.09, ymax = 0.06,
        xtick distance = 5,
        ytick distance = 0.03,
        xlabel={$time\;[s]$},
        ylabel={$V_z\;[km/s]$},
        grid = both,
        grid style = {dotted},
        minor tick num = 1,
        major grid style = {lightgray!75},
        minor grid style = {lightgray!75},
        width = 0.85\textwidth,
        height = 0.50\textwidth,
        %scale only axis,
        %legend cell align = {left},
        %legend pos = north east,
        legend style={at={(0.5,-0.3)},
        anchor=north,legend columns=4},
        legend cell align = {left},
    ]
     

    \nextgroupplot[title={title1}]
     

    \addplot[smooth, black, ultra thick] table [x = {t1a}, y = {vz1a}] {\DataTableA};
    \addplot[smooth, Lavender, very thick] table [x = {t1b}, y = {vz1b}] {\DataTableA};
    \addplot[smooth, Violet, very thick] table [x = {t1c}, y = {vz1c}] {\DataTableA};
    \addplot[smooth, Emerald, dotted, ultra thick] table [x = {t2}, y = {vz2}] {\DataTableA};




    \nextgroupplot[title={title2},
    xmin = 0, xmax = 15,
    ymin = -0.12, ymax = 0.06,
    ytick distance = 0.03,
    legend entries={n1(k),n1(k-2),n1(k-4),n2(k),n2(j),n2(j+1.5),n2(j+3)},
    ]

    \addlegendimage{black, no markers, very thick}
    \addlegendimage{Lavender, no markers, very thick}
    \addlegendimage{Violet, no markers, very thick}
    \addlegendimage{Emerald, dotted, no markers, ultra thick}
    \addlegendimage{Apricot, no markers, very thick}
    \addlegendimage{RedOrange, no markers, very thick}
    \addlegendimage{MidnightBlue, no markers, very thick}


    \addplot[smooth, Apricot, ultra thick] table [x = {t1a}, y = {vz1a}] {\DataTableB};
    \addplot[smooth, RedOrange, very thick] table [x = {t1b}, y = {vz1b}] {\DataTableB};
    \addplot[smooth, MidnightBlue, very thick] table [x = {t1c}, y = {vz1c}] {\DataTableB};
    

    
 
\end{groupplot}
\end{tikzpicture}
\caption{some random caption}
\end{figure}

\end{document}
4
  • Unless you provide an MWE, it's hard to say. But I guess you can try passing scaled y ticks=true to the axis environment if you haven't.
    – SolidMark
    Jun 25, 2021 at 20:11
  • Thanks for having attempted @M.A.Bromuela, unfortunately it doesn't solve the problem. It's actually hard to reproduce the problem with a MWE, because, as I said, I've a lot of groupplots that use the same group "structure", where this kind of issue doesn't happen. They all have the 10^-2 on top when necessary. Only the plot I've uploaded here differs from the others. I can update the first post with the structure I use, but I'm afraid I can't provide you the whole data.dat file.
    – Catarella
    Jun 26, 2021 at 10:03
  • You don't need to give whole data. What you may do is reproduce the code that gives the problem. That is the code for the plot with the scaled notation not appearing on top. It looks like the second plot corresponds to DataTableB and the fact that there is -0.12 at the lower y-axis which may be scaled to 10^-1 hence not having a common factor.
    – SolidMark
    Jun 26, 2021 at 10:24
  • Is there a way to force the algorithm to write -12 and then put 10^-2 on top ? The actual values arrive to almost -0.11, but I put -0.12 as ymin to keep a certain distance from the x-axis. Is the double digit number (i.e. 12) that confuse the code?
    – Catarella
    Jun 26, 2021 at 10:40

1 Answer 1

1

Okay so I just made some dummy table to try out your code. And the only line you needed to add was scaled y ticks = base x:y. For DataTableB, in this case you had to manually pass scaled y ticks = base 10:2 which then forced -0.12 to display as -12 thus allowing to scale with common factor. I commented out lines that render uncompilable or unnecessary for giving the solution.

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{pgf,pgfplots,pgfplotstable}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{colormaps}
\usepgfplotslibrary{groupplots}

\begin{document}


\begin{figure}[htbp]
    \centering
    \pgfplotstableread{table.txt}{\DataTableA}
    \pgfplotstableread{table.txt}{\DataTableB}
 
 
    \begin{tikzpicture}[scale=0.9]
        \begin{groupplot}[group style={
        group name=vztcompcross,
        group size=1 by 2,
        xlabels at=edge bottom,
        ylabels at=edge left,
        vertical sep=4em
        },
        xmin = 0, xmax = 30,
        ymin = -0.09, ymax = 0.06,
        xtick distance = 5,
        ytick distance = 0.03,
        xlabel={$time\;[s]$},
        ylabel={$V_z\;[km/s]$},
        grid = both,
        grid style = {dotted},
        minor tick num = 1,
        major grid style = {lightgray!75},
        minor grid style = {lightgray!75},
        width = 0.85\textwidth,
        height = 0.50\textwidth,
        %scale only axis,
        %legend cell align = {left},
        %legend pos = north east,
        legend style={at={(0.5,-0.3)},
        anchor=north,legend columns=4},
        legend cell align = {left},
        scaled ticks=true
    ]
     

    \nextgroupplot[title={title1}]
     

    \addplot[smooth, black, ultra thick] table [x = {t1a}, y = {vz1a}] {\DataTableA};
    %\addplot[smooth, Lavender, very thick] table [x = {t1b}, y = {vz1b}] {\DataTableA};
    %\addplot[smooth, Violet, very thick] table [x = {t1c}, y = {vz1c}] {\DataTableA};
    %\addplot[smooth, Emerald, dotted, ultra thick] table [x = {t2}, y = {vz2}] {\DataTableA};

     \nextgroupplot[
     scaled y ticks=base 10:2 %<----------- Here
     title={title2},
    xmin = 0, xmax = 15,
    ymin = -0.12, ymax = 0.06,
    ytick distance = 0.03,
   % legend entries={n1(k),n1(k-2),n1(k-4),n2(k),n2(j),n2(j+1.5),n2(j+3)},
    ]

%    \addlegendimage{black, no markers, very thick}
%    \addlegendimage{Lavender, no markers, very thick}
%    \addlegendimage{Violet, no markers, very thick}
%    \addlegendimage{Emerald, dotted, no markers, ultra thick}
%    \addlegendimage{Apricot, no markers, very thick}
%    \addlegendimage{RedOrange, no markers, very thick}
%    \addlegendimage{MidnightBlue, no markers, very thick}
%
%
    \addplot[smooth, Apricot, ultra thick] table [x = {t1a}, y = {vz1a}] {\DataTableB};
%    \addplot[smooth, RedOrange, very thick] table [x = {t1b}, y = {vz1b}] {\DataTableB};
%    \addplot[smooth, MidnightBlue, very thick] table [x = {t1c}, y = {vz1c}] {\DataTableB};
%    
%
%    
% 
\end{groupplot}
\end{tikzpicture}
\caption{some random caption}
\end{figure}

\end{document}

Setting base=10:2

By setting scaled y ticks=base 10:1, you get

Setting base=10:1

3
  • Thank you very much @M.A.Bromuela, it worked smoothly. And thank you also for having made some dummy tables by yourself before I could provide them for you... very kind!
    – Catarella
    Jun 26, 2021 at 12:01
  • Kein problem. Regards.
    – SolidMark
    Jun 26, 2021 at 12:06
  • Let me add to the answer why PGFPlots decided to use scaling for the first plot in the question and not for the second. This is because of the keys scale ticks below exponent which has the default value -1 (and scale ticks above exponent which has the default value 3). So I guess that for the lower plot at least one value is above 0.1 which results in no scaling. Jun 27, 2021 at 20:27

You must log in to answer this question.

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