2

Hello fellows and folks!

I am trying to get rid of the .10^-3 in the x label, but something is wrong and I cannot find the bug.

I tried with x tick label style={/pgf/number format/.cd,fixed,fixed zerofill,precision=3}, but it throws an error.

This is the code and the plot it yields:

\documentclass{standalone}
\usepackage{subcaption}
\usepackage{caption}
\usepackage{pgfplots, pgfplotstable}
\usetikzlibrary{positioning}
\pgfplotsset{compat=1.16,width=0.98\textwidth}
%\pgfplotsset{compat=1.16,width=0.98\textwidth}

\usepackage{tikz}
\usepackage[english,spanish]{babel}         % multilenguaje
\decimalpoint

\begin{document}



    % This file was created by matplotlib2tikz v0.7.4.
    \begin{tikzpicture}



    \begin{axis}[
    axis line style={black},
    legend cell align={left},
    legend style={draw=black},
    tick align=outside,
    x grid style={dashed,black!60},
    xlabel={ $\gamma{1}$},
    xmajorticks=true,
    xmin=-0.0004, xmax=0.0084,
    xtick style={color=black},
    %x tick label style={/pgf/number format/.cd,fixed,fixed zerofill,precision=3},
    y grid style={dashed,black!60},
    ylabel={RMSE},
    ymajorticks=true,
    ymin=0.930295, ymax=1.135005,
    ytick style={black},
    xtick align=inside,
    ytick align=inside,
    grid = both]
\addplot [mark =o,line width=1pt,blue, mark size=1pt]
table {%
0 1.1257
0.001 0.9556
0.002 0.9449
0.003 0.9415
0.004 0.9399
0.005 0.9398
0.006 0.9396
0.007 0.9397
0.008 0.9398
};
\addlegendentry{Error}
\end{axis}

\end{tikzpicture}

 \end{document}

enter image description here

  • 1
    You can add scaled x ticks=false to the axis options but then the distance between the ticks will be rather small. – marmot Jun 12 at 22:45
  • Thank you very much!!! – NaveganTeX Jun 12 at 22:53
1

You can get rid of the multiplier by adding scaled x ticks=false to the axis options, but then the ticks will be dense. Hence I propose to only print every other x tick.

\documentclass{standalone}
\usepackage{subcaption}
\usepackage{caption}
\usepackage{pgfplots, pgfplotstable}
\usetikzlibrary{positioning}
\pgfplotsset{compat=1.16,width=0.98\textwidth}
%\pgfplotsset{compat=1.16,width=0.98\textwidth}

\usepackage{tikz}
\usepackage[english,spanish]{babel}         % multilenguaje
\decimalpoint

\begin{document}



    % This file was created by matplotlib2tikz v0.7.4.
    \begin{tikzpicture}



    \begin{axis}[
    axis line style={black},
    legend cell align={left},
    legend style={draw=black},
    tick align=outside,
    x grid style={dashed,black!60},
    xlabel={ $\gamma{1}$},
    xmajorticks=true,
    xmin=-0.0004, xmax=0.0084,
    xtick style={color=black},
    %x tick label style={/pgf/number format/.cd,fixed,fixed zerofill,precision=3},
    scaled x ticks=false,xticklabel=\pgfmathfloatparsenumber{\tick}%
    \pgfmathfloattomacro{\pgfmathresult}{\F}{\M}{\E}%
    \pgfmathtruncatemacro{\itest}{\M}%
    \ifodd\itest%
    \else%
    $\pgfmathprintnumber{\tick}$
    \fi,%xtick distance=2,
    y grid style={dashed,black!60},
    ylabel={RMSE},
    ymajorticks=true,
    ymin=0.930295, ymax=1.135005,
    ytick style={black},
    xtick align=inside,
    ytick align=inside,
    grid = both]
\addplot [mark =o,line width=1pt,blue, mark size=1pt]
table {%
0 1.1257
0.001 0.9556
0.002 0.9449
0.003 0.9415
0.004 0.9399
0.005 0.9398
0.006 0.9396
0.007 0.9397
0.008 0.9398
};
\addlegendentry{Error}
\end{axis}

\end{tikzpicture}

\end{document}

enter image description here

1

I (personally) don't like to have ticklabels like in your (OPs) code and I also don't like the ones shown in marmot's answer. I prefer adding the scaling to the axis labels.

Of course one could simply remove/empty the tick scale binop and add the scaling by hand to the axis label. But I like to have more automated solutions which of course is a bit more complicated ...

For details please have a look at the comments in the code.

% used PGFPlots v1.16
% (adapted from <https://tex.stackexchange.com/a/352016/95441>)
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{
        compat=1.3,
        % (assuming you use this style of diagram elsewhere, too,
        %  create a style for simpler reuse and especially keeping it consistent
        %  in case you change something)
        my axis style/.style={
            axis line style={black},
            legend cell align={left},
            legend style={draw=black},
            tick align=outside,
            x grid style={dashed,black!60},
            width=0.98\textwidth,
            xmajorticks=true,
            xtick style={color=black},
            y grid style={dashed,black!60},
            ymajorticks=true,
            ytick style={black},
            grid=both,
            xtick align=inside,
            ytick align=inside,
        },
        % create a new style to move the `tick scale label' to the axis labels
        tick scale labels in axis labels/.code={
            \pgfkeysgetvalue{/pgfplots/xtick scale label code/.@cmd}\temp
            % remember the original value of 'xtick scale label code':
            \pgfkeyslet{/pgfplots/xtick scale label code orig/.@cmd}\temp
            %
            \pgfkeysalso{
                % simply remember the value in some global macro:
                xtick scale label code/.code={
                    \gdef\xTickScale{##1}
                },
                % now, _modify_ any user-specified value of 'xlabel' by
                % prepending the tick scale label.
                % In order to evaluate this modification AFTER the user
                % wrote "xlabel={$x$}", we add it to 'every axis':
                every axis/.append style={
                    % because we don't need the "binop" in this context just
                    % set it to nothing
                    tick scale binop={},
                    xlabel/.add={%
                        \pgfmathparse{-\xTickScale}%
                        \pgfplotsset{
                            xtick scale label code orig={%
                                \pgfmathprintnumber[fixed,int detect]{\pgfmathresult} \,%
                            }
                        }
                    }{},
                },
            }
        },
    }
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        % activate/load the created styles
        my axis style,
        tick scale labels in axis labels,
        %
        xlabel={$\gamma{1}$},
        xmin=-0.0004,
        xmax=0.0084,
        ylabel={RMSE},
        ymin=0.930295,
        ymax=1.135005,
    ]
        \addplot [
            mark=o,
            line width=1pt,
            blue,
            mark size=1pt,
        ] table [
%            % (unfortunately this throughs an "dimension too large" error.
%            %  Otherwise this would be the simplest solution.)
%            x expr=\thisrowno{0}*1e3,
        ] {
            0 1.1257
            0.001 0.9556
            0.002 0.9449
            0.003 0.9415
            0.004 0.9399
            0.005 0.9398
            0.006 0.9396
            0.007 0.9397
            0.008 0.9398
        };
        \addlegendentry{Error}
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

  • As always... it is a matter of taste! Thank you for your response! – NaveganTeX Jun 14 at 0:08

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.