#60 Scaled ticks not working when axis limit is 0

closed-fixed
nobody
None
5
2013-01-22
2012-12-21
Jake
No

If one of the axis limits is exactly 0, scaled ticks has no effect. If the value is perturbed slightly, it works.

MWE:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest,width=6cm}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
scaled y ticks=true,
ymax=0.0008,
ymin=0,
%ymin=1e-24 % Works if this is line is uncommented
]
\addplot [cyan, domain=0:10] {0.0001*x};
\end{axis}
\end{tikzpicture}
\end{document}

This could be fixed by adding a check for 0 values in \pgfplots@init@scaled@tick@for#1, but I'm not sure whether that's the cleanest approach:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=newest,width=6cm}

%
\makeatletter
\def\pgfplots@init@scaled@tick@for#1{%
\global\def\pgfplots@glob@TMPa{0}%
\expandafter\pgfplotslistcheckempty\csname pgfplots@prepared@tick@positions@major@#1\endcsname
\ifpgfplotslistempty
% we have no tick labels. Omit the tick scale label as well!
\else
\begingroup
\ifcase\csname pgfplots@scaled@ticks@#1@choice\endcsname\relax
% CASE 0 : scaled #1 ticks=false: do nothing here.
\or
% CASE 1 : scaled #1 ticks=true:
%--------------------------------
% the \pgfplots@xmin@unscaled@as@float is set just before the data
% scale transformation is initialised.
%
% The variables are empty if there is no datascale transformation.
\expandafter\let\expandafter\pgfplots@cur@min@unscaled\csname pgfplots@#1min@unscaled@as@float\endcsname
\expandafter\let\expandafter\pgfplots@cur@max@unscaled\csname pgfplots@#1max@unscaled@as@float\endcsname
%
\ifx\pgfplots@cur@min@unscaled\pgfutil@empty
\edef\pgfplots@loc@TMPa{\csname pgfplots@#1min\endcsname}%
\expandafter\pgfmathfloatparsenumber\expandafter{\pgfplots@loc@TMPa}%
\let\pgfplots@cur@min@unscaled=\pgfmathresult
\edef\pgfplots@loc@TMPa{\csname pgfplots@#1max\endcsname}%
\expandafter\pgfmathfloatparsenumber\expandafter{\pgfplots@loc@TMPa}%
\let\pgfplots@cur@max@unscaled=\pgfmathresult
\fi
%
\expandafter\pgfmathfloat@decompose@E\pgfplots@cur@min@unscaled\relax\pgfmathfloat@a@E
\expandafter\pgfmathfloat@decompose@E\pgfplots@cur@max@unscaled\relax\pgfmathfloat@b@E
\ifnum\pgfmathfloat@a@E=0%
\pgfmathfloat@a@E=\pgfmathfloat@b@E%
\fi%
\ifnum\pgfmathfloat@b@E=0%
\pgfmathfloat@b@E=\pgfmathfloat@a@E%
\fi%
\ifnum\pgfmathfloat@b@E<\pgfmathfloat@a@E%
\pgfmathfloat@b@E=\pgfmathfloat@a@E%
\fi
\xdef\pgfplots@glob@TMPa{\pgfplots@scale@ticks@above@exponent}%
\expandafter\ifnum\pgfplots@glob@TMPa<\pgfmathfloat@b@E
% ok, scale it:
\multiply\pgfmathfloat@b@E by-1
\xdef\pgfplots@glob@TMPa{\the\pgfmathfloat@b@E}%
\else
\xdef\pgfplots@glob@TMPa{\pgfplots@scale@ticks@below@exponent}%
\expandafter\ifnum\pgfplots@glob@TMPa>\pgfmathfloat@b@E
% ok, scale it:
\multiply\pgfmathfloat@b@E by-1
\xdef\pgfplots@glob@TMPa{\the\pgfmathfloat@b@E}%
\else
% no scaling necessary:
\xdef\pgfplots@glob@TMPa{0}%
\fi
\fi
\or
% CASE 2 : scaled #1 ticks=base 10:
%--------------------------------
\c@pgf@counta=\csname pgfplots@scaled@ticks@#1@arg\endcsname\relax
%\multiply\c@pgf@counta by-1
\xdef\pgfplots@glob@TMPa{\the\c@pgf@counta}%
\or
% CASE 3 : scaled #1 ticks=real:
%--------------------------------
\pgfmathfloatparsenumber{\csname pgfplots@scaled@ticks@#1@arg\endcsname}%
\global\let\pgfplots@glob@TMPa=\pgfmathresult
\or
% CASE 4 : scaled #1 ticks=manual:
\expandafter\global\expandafter\let\expandafter\pgfplots@glob@TMPa\csname pgfplots@scaled@ticks@#1@arg\endcsname
\fi
\endgroup
\fi
\expandafter\let\csname pgfplots@tick@scale@#1\endcsname=\pgfplots@glob@TMPa%
}
\makeatother
%%

\begin{document}
\begin{tikzpicture}
\begin{axis}[
scaled y ticks=true,
ymax=0.0008,
ymin=0,
%ymin=1e-24 % Works if this is line is uncommented
]
\addplot [cyan, domain=0:10] {0.0001*x};
\end{axis}
\end{tikzpicture}
\end{document}

Discussion

  • Christian Feuersänger

    • status: open --> closed-fixed
     
  • Christian Feuersänger

    Thanks for the report and the suggested solution! I have fixed it. Will become part of the next stable.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks