Avoid rounding issue in pgfplots with log ticks with fixed point

Flogo 05/16/2017. 2 answers, 61 views
tikz-pgf pgfplots

The tick for 1.1 in the following plot is slightly lower than the actual value for 1.1. This becomes even more visible when adding an extra tick at 1.1. Is there a way I can have the ticks at the place that corresponds to their labels?

There is a related question (How to prevent rounded and duplicated tick labels in pgfplots with fixed precision?) but it only discusses how to get rid of wrong labels. I prefer if there was a way to keep the labels but have them at the correct position.

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ymin=1,
    ymax=1.2,
    log ticks with fixed point,
    ymode=log
]
\addplot
coordinates {(1, 1.1) (2, 1.1) };

\end{axis}
\end{tikzpicture}
\end{document}

log axis rounding issue

2 Comments
2 John Kormylo 05/16/2017
That's because the tick mark is actually at 10^0.04 or about 1.096.
Flogo 05/17/2017
Thanks, I suspected as much. My question is about if there is a way to avoid the ticks at positions that match their label. I guess the issue is that tick position is determined before the label content.

2 Answers


John Kormylo 05/16/2017.

To put the tick marks where they belong, specify them by value.

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ymin=1,
    ymax=1.2,
    log ticks with fixed point,
    ymode=log,
    ytick={1,1.05,1.1,1.15,1.2}
]
\addplot
coordinates {(1, 1.1) (2, 1.1) };

\end{axis}
\end{tikzpicture}
\end{document}

demo

2 comments
Flogo 05/17/2017
Thanks again, but this is not an option for me. I'm working on a script that generates plots automatically, so I don't know in advance where the ticks should go (or how many there should be). I guess I could re-implement the automatic tick placement of pgfplots, but hoped there is a better way.
John Kormylo 05/17/2017
You already specified ymin and ymax. All you need is to calculate the intermediate values and store them in an array/string. See also tex.stackexchange.com/questions/317347/… and tex.stackexchange.com/questions/269222/…

hzhr 05/16/2017.

If you have already the coordinates in the logarithmic domain just remove the ymode=log in the axis environment.

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.13}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    ymin=1,
    ymax=1.2,
    log ticks with fixed point,
]
\addplot
coordinates {(1, 1.1) (2, 1.1) };

\end{axis}
\end{tikzpicture}
\end{document}
1 comments
Flogo 05/17/2017
I don't understand what you mean by "in the logarithmic domain". In your example the y-axis is linear (so for example the distance between 1 and 10 would be different from the distance between 10 and 100). If you suggest to plot (x, log_10(y) ) instead of (x,y), that would work but the labels would be wrong then (for example y=100 would show up at log_10(100) = 2 instead of 100). Am I missing something?

HighResolutionMusic.com - Download Hi-Res Songs

1 Alan Walker

Diamond Heart flac

Alan Walker. 2018. Writer: Alan Walker;Sophia Somajo;Mood Melodies;James Njie;Thomas Troelsen;Kristoffer Haugan;Edvard Normann;Anders Froen;Gunnar Greve;Yann Bargain;Victor Verpillat;Fredrik Borch Olsen.
2 Sia

I'm Still Here flac

Sia. 2018. Writer: Sia.
3 Cardi B

Taki Taki flac

Cardi B. 2018. Writer: Bava;Juan Vasquez;Vicente Saavedra;Jordan Thorpe;DJ Snake;Ozuna;Cardi B;Selena Gomez.
4 Little Mix

Woman Like Me flac

Little Mix. 2018. Writer: Nicki Minaj;Steve Mac;Ed Sheeran;Jess Glynne.
5 Halsey

Without Me flac

Halsey. 2018. Writer: Halsey;Delacey;Louis Bell;Amy Allen;Justin Timberlake;Timbaland;Scott Storch.
6 Lady Gaga

I'll Never Love Again flac

Lady Gaga. 2018. Writer: Benjamin Rice;Lady Gaga.
7 Bradley Cooper

Shallow flac

Bradley Cooper. 2018. Writer: Andrew Wyatt;Anthony Rossomando;Mark Ronson;Lady Gaga.
8 Bradley Cooper

Always Remember Us This Way flac

Bradley Cooper. 2018. Writer: Lady Gaga;Dave Cobb.
9 Kelsea Ballerini

This Feeling flac

Kelsea Ballerini. 2018. Writer: Andrew Taggart;Alex Pall;Emily Warren.
10 Mako

Rise flac

Mako. 2018. Writer: Riot Music Team;Mako;Justin Tranter.
11 Dewain Whitmore

Burn Out flac

Dewain Whitmore. 2018. Writer: Dewain Whitmore;Ilsey Juber;Emilio Behr;Martijn Garritsen.
12 Avril Lavigne

Head Above Water flac

Avril Lavigne. 2018. Writer: Stephan Moccio;Travis Clark;Avril Lavigne.
13 Khalid

Better flac

Khalid. 2018. Writer: Charlie Handsome;Jamil Chammas;Denis Kosiak;Tor Erik Hermansen;Mikkel Stoleer Eriksen;Khalid.
14 Lady Gaga

Look What I Found flac

Lady Gaga. 2018. Writer: DJ White Shadow;Nick Monson;Mark Nilan Jr;Lady Gaga.
15 Deep Chills

Run Free flac

Deep Chills. 2018.
16 Dynoro

In My Mind flac

Dynoro. 2018. Writer: Georgi Kay;Feenixpawl;Ivan Gough.
17 Charli XCX

1999 flac

Charli XCX. 2018. Writer: Charli XCX;Troye Sivan;Leland;Oscar Holter;Noonie Bao.
18 NCT 127

Regular (English Version) flac

NCT 127. 2018.
19 Lukas Graham

Love Someone flac

Lukas Graham. 2018. Writer: Don Stefano;Morten "Rissi" Ristorp;Morten "Pilo" Pilegaard;Jaramye Daniels;James Alan;David LaBrel;Lukas Forchhammer Graham.
20 Rita Ora

Let You Love Me flac

Rita Ora. 2018. Writer: Rita Ora.

Related questions

Hot questions

Language

Popular Tags