# How to make logarithmic axis "readable"?

How can I make a logarithmic axis more readable? I have many plots that look similar to this one:

The problem is in the y axis. Anyone can imagine what 10^5 represents, or 10^6. It is not so easy with the other yticks. I can not use a linear axis, since if I do so the difference between the functions represented is not visible anymore.

What feature of pgfplots could I use to make LaTeX write 1.58e6 instead of 10^6.2, 3.98e5 instead of 10^6.2, etc?

Here is a MWE:

\documentclass[]{article}

\usepackage{graphicx}
\usepackage{pgfplots, pgfplotstable, filecontents}
\pgfplotsset{compat=newest,width=13.5cm}

\begin{document}

\begin{figure}[h]
\centering
\begin{tikzpicture}
\begin{axis}[
xmode=log,
ymode=log,
log basis x={2},
log basis y={10},
ytickten={4.6,4.8,...,7},
ymajorgrids,
height=7cm,width=14.5cm,
xlabel = xLabel,
ylabel = yLabel,
y label style={at={(axis description cs:-0.07,.5)},anchor=south},
xticklabel style={text height=1.5ex}, % To make sure the text labels are nicely aligned
xtick=data
]
\pgfplotstableread{mwe.dat} \tableRAW
\foreach \p in {6,10,14,18,22,30,34,38,42,46} {\addplot table [y index = \p] from \tableRAW;}
\end{axis}
\end{tikzpicture}
\caption{Caption}
\end{figure}

\end{document}


The mwe.dat has the following content, for instance:

ProblemSize N[512]_[128]__T N[512]_[128]_O  N[512]_[128]_B  N[512]_[128]_C  N[1024]_[128]_E_T   N[1024]_[128]_O N[1024]_[128]_B N[1024]_[128]_C N[2048]_[128]_E_T   N[2048]_[128]_O N[2048]_[128]_B N[2048]_[128]_C N[4096]_[128]_E_T   N[4096]_[128]_O N[4096]_[128]_B N[4096]_[128]_C N[8192]_[128]_E_T   N[8192]_[128]_O N[8192]_[128]_B N[8192]_[128]_C N[16384]_[128]_E_T  N[16384]_[128]_O    N[16384]_[128]_B    N[16384]_[128]_C    N[128]_[128]_E_T    N[128]_[128]_O  N[128]_[128]_B  N[128]_[128]_C  N[256]_[128]_E_T    N[256]_[128]_O  N[256]_[128]_B  N[256]_[128]_C  N[512]_[128]_E_T    N[512]_[128]_O  N[512]_[128]_B  N[512]_[128]_C  N[1024]_[128]_E_T   N[1024]_[128]_ON[1024]_[128]_B  N[1024]_[128]_C N[2048]_[128]_E_T   N[2048]_[128]_O N[2048]_[128]_B N[2048]_[128]_C N[4096]_[128]_E_T   N[4096]_[128]_O N[4096]_[128]_B N[4096]_[128]_C
256 0.97228 1.02851e+06 21.4983 0.03109 0.97389 1.02681e+06 22.4082 0.04458 0.85456 1.17019e+06 20.3105 0.06449 0.6619  1.5108e+06  13.0575 0.0108  0.67471 1.48212e+06 13.1551 0.17767 0.67388 1.48394e+06 13.39530.01469  0.65627 1.52376e+06 15.5989 0.05612 0.72857 1.37255e+06 13.5689 0.01491 0.92109 1.08567e+06 11.6451 0.04136 0.99086 1.00922e+06 8.48264 0.03864 0.98233 1.01799e+06 8.44543 0.03509 0.98701 1.01316e+06 8.539090.03407
512 1.07073 933942  24.8693 0.11453 1.03132 969631  25.0253 0.00683 0.99106 1.00902e+06 23.7109 0.0312  0.96503 1.03624e+06 20.9663 0.04173 0.86419 1.15715e+06 13.4905 0.02369 0.87189 1.14693e+06 14.0297 0.00568 0.724331.38059e+06  15.1526 0.04204 0.90113 1.10972e+06 13.4288 0.09596 1.11974 893064  16.1055 0.01536 1.50563 664173  11.7053 0.01135 1.77749 562591  8.597   0.14894 1.78091 561510  8.66193 0.02654
1024    1.11973 893072  25.9047 0.01732 1.10779 902698  26.5268 0.00224 1.08851 918687  24.1258 0.11408 1.12235 890987  24.4282 0.00397 1.20571 829386  21.3686 0.19148 1.26128 792845  14.4341 0.03939 0.84159 1.18823e+06 16.65320.0232   1.02138 979067  13.2784 0.15388 1.43999 694449  15.0922 0.14563 1.76639 566126  13.4751 0.0054  2.69765 370693  13.3329 0.38205 3.36242 297404  8.93883 0.14005
2048    1.19361 837794  27.6662 0.01022 1.1495  869943  27.6528 0.056   1.14584 872722  23.7522 0.01878 1.25679 795677  24.428  0.122   1.34877 741416  24.415  0.02426 1.65895 602790  22.1781 0.13764 0.91282 1.09551e+06 18.54360.00182  1.12933 885480  14.0755 0.01297 1.65897 602783  14.5747 0.05213 2.40369 416027  13.1842 0.11423 3.15759 316697  13.4233 0.02508 5.05221 197933  11.7823 0.01389
4096    1.32566 754341  28.9796 0.18622 1.23941 806835  29.674  0.00617 1.2321  811622  27.3659 0.04763 1.34405 744019  23.8127 0.0095  1.59149 628341  24.1053 0.0044  2.24884 444673  25.0658 0.14431 1.00368 996333  20.6166 0.006351.28812  776325  15.1566 0.01053 1.83921 543711  16.1332 0.01447 2.81505 355233  12.8139 0.03186 4.40357 227088  12.8754 0.01846 5.91251 169132  13.439  0.02888
8192    1.65467 604350  36.9892 0.03403 1.39874 714929  31.556  0.0343  1.33747 747680  28.1655 0.0432  1.4603  684790  24.3148 0.06718 1.77654 562891  23.5358 0.06063 2.62917 380348  26.2985 0.03223 1.27283 785650  25.8913 0.021211.42514  701685  17.9831 0.0196  1.99235 501919  18.3988 0.02879 3.10529 322031  13.4503 0.04553 5.23139 191153  13.1992 0.25768 8.41015 118903  13.3096 0.33291
16384   1.78045 561655  36.5921 0.09871 1.69525 589883  38.6196 0.10832 1.47453 678182  29.9039 0.23807 1.57552 634711  28.4095 0.0993  1.94293 514686  24.4086 0.05438 2.90079 344733  26.786  0.09028 1.44748 690855  28.3414 0.075061.68019  595170  23.6952 0.08263 2.31482 431999  20.5626 0.45375 3.31934 301264  14.6222 0.19763 5.76202 173550  13.5533 0.2047  9.99136 100086  13.3392 0.45562
32768   1.88014 531875  37.0423 0.36639 1.87151 534327  41.2633 0.59267 1.77574 563145  35.9772 0.3406  1.73167 577477  29.444  0.32351 2.11832 472072  25.8418 0.34864 3.08201 324463  27.9683 0.38472 1.69134 591247  31.7095 0.315451.90899  523837  27.6826 0.47064 2.63369 379695  26.4278 0.30212 3.51509 284487  16.8641 0.40678 6.12792 163187  15.0831 0.49327 11.227  89070   17.5178 0.50585
65536   1.99541 501150  39.2376 0.97965 2.11309 473240  38.9739 0.85585 1.92737 518841  38.8971 0.79071 2.04267 489555  35.6165 0.7208  2.23172 448084  29.9107 0.81979 3.26429 306345  30.0811 0.81524 1.75929 568411  33.4318 0.81611.98472   503849  28.562  0.70891 2.78507 359057  28.1771 0.98133 4.11666 242915  21.5141 0.73537 6.37485 156866  16.3491 0.49165 11.8903 84101   18.9686 0.70702
131072  2.21894 450665  41.3931 3.56014 2.2088  452734  40.4699 3.17495 2.23575 447277  38.7189 2.43021 2.2738  439792  37.1943 2.34785 2.60879 383319  35.4009 1.99836 3.34132 299282  31.831  1.76457 2.00429 498929  34.285  2.492292.22912  448607  26.9544 2.33051 3.07903 324777  31.6439 2.24561 4.42664 225904  23.1791 2.27318 6.79527 147161  20.4874 2.02689 12.8124 78049   27.7722 2.37168
262144  2.62945 380307  41.5732 9.95812 2.56275 390205  43.4339 8.8167  2.49363 401021  40.9032 5.81198 2.57011 389088  37.4565 4.92038 2.89366 345583  36.5665 4.47881 3.75893 266033  37.8185 4.3511  2.16293 462335  34.2238 7.096932.43386  410869  30.4305 5.94276 3.23885 308751  33.8836 5.24693 4.52934 220782  22.8621 4.84698 7.71618 129597  23.1346 4.65529 13.0328 76729   24.1635 4.74844
524288  3.17954 314510  49.4433 19.7045 2.71247 368667  43.4528 15.9456 2.77835 359925  40.6722 13.4277 2.9079  343890  39.2715 10.2547 3.25927 306817  36.9935 9.09368 4.1093  243350  40.1475 8.65571 2.37853 420427  32.8675 14.46572.69804  370639  29.5104 13.7364 3.46947 288228  33.5227 12.5016 4.91092 203627  23.8064 9.78272 8.04862 124244  23.5891 9.04645 13.1739 75907   24.3282 9.25118
1.04858e+06 3.41797 292571  50.2035 25.2329 3.18887 313590  50.3884 25.2264 3.00674 332586  41.8184 26.6924 3.2022  312285  40.5863 27.495  3.6855  271333  38.4739 28.9153 4.63748 215634  40.7343 29.5919 2.78837 358632  43.1375 21.04533.02078  331040  32.7593 23.5182 3.85434 259447  34.108  25.8087 5.19604 192454  25.6156 27.7838 8.22863 121526  24.0932 25.1218 14.8478 67350   24.4182 29.1166
2.09715e+06 3.74751 266843  51.689  31.0401 3.53613 282795  52.208  32.766  3.30274 302778  42.156  37.4918 3.55384 281385  41.3582 45.5133 4.09515 244191  38.5735 54.6245 5.27339 189631  40.4359 60.7951 3.22626 309956  48.8833 25.41263.42453  292010  35.6319 30.445  4.07128 245622  32.6033 37.1324 5.38778 185605  26.4322 41.9166 8.59486 116348  24.7167 38.584  15.1875 65843   22.5894 49.4032
4.1943e+06  3.94776 253308  51.6652 42.4162 3.84623 259994  53.76   36.6812 3.84898 259809  52.4399 44.5894 3.94163 253702  42.1453 56.8887 4.54418 220061  39.9494 72.8677 5.69155 175699  42.5106 85.9424 3.4007  294057  46.91   31.63   3.68056 271697  40.7103 35.6234 4.6235  216286  46.854  43.6437 5.54189 180443  28.4925 52.7722 8.77397 113973  26.8077 48.7628 15.3429 65176   24.394  62.0138
8.38861e+06 4.45432 224501  53.2226 51.6686 4.32302 231319  54.5407 45.1471 4.30989 232024  53.5507 49.7948 4.54465 220038  49.0005 65.3684 5.11556 195482  41.4991 83.9613 6.23269 160444  42.6107 101.735 3.67634 272009  53.5884 36.32053.92525  254760  41.8977 39.4851 4.86561 205524  44.886  48.8251 6.20439 161176  33.1251 59.0889 8.97228 111454  27.3635 55.796  15.6522 63888   24.7134 69.1079

• A quick check of the pgfplots manual suggests that you should read up about log plot exponent style.
– user30471
Commented Jul 25, 2014 at 13:43

## 1 Answer

The comment by Andrew is not sufficient, because log plot exponent style only affects the format of the exponent itself; it doesn't allow you to change the base at all.

I'm not totally convinced that what you're asking for is a good idea. As you'll see below, you lose the immediate clue that you're looking at a logarithmic scale, and have to parse the numbers in your head to figure it out. Nonetheless, an attempt at a solution follows, and I'll let you decide:

I defined a new style sci log y ticks based on log ticks with fixed point from pgfplots.code.tex (v1.10). My style uses /pgf/number format's sci,sci zerofill,precision=2. If you truly want the literal 1.58e6 (I don't recommend this), you could add the option verbatim in that section of the code. I have it commented in the example below.

There is surely a better way to make this only apply to the y-axis. I made it work by re-setting xticklabel to use the standard logarithmic representation. The relevant code is:

xticklabel={$\pgfkeysvalueof{/pgfplots/log basis x}^{\pgfmathprintnumber[std]{\tick}}$},


so it will respect an arbitrary setting of log basis x in the axis options.

## Complete Code

I stripped all extraneous options and data from your example, to show the changes clearly and make working on the solution simpler for me. :-) All of your customizations will still work though.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}

%%% begin new style, based on /pgfplots/log ticks with fixed point from pgfplots.code.tex
\makeatletter
\pgfplotsset{
sci log y ticks/.style={
/pgfplots/log number format basis/.code 2 args={
\begingroup
\edef\pgfplots@exponent{##2}%
\pgfkeysalso{/pgf/fpu}%
\pgfqkeys{/pgf/number format}{%
sci,sci zerofill,%verbatim, %<-- uncomment for literal 1.58e6
precision=2,
}%
\ifdim##1pt=10pt
\def\pgfplots@baselog{2.30258509299405}%
\else
\pgfmathparse{ln(##1)}%
\let\pgfplots@baselog=\pgfmathresult
\fi
\pgfmathparse{exp(\pgfplots@exponent*\pgfplots@baselog)}%
\pgfmathprintnumber[#1]\pgfmathresult
\endgroup
},
% reset the x-axis ticks... there must be a cleaner way to handle this
xticklabel={$\pgfkeysvalueof{/pgfplots/log basis x}^{\pgfmathprintnumber[std]{\tick}}$},
},
}
\makeatother
%%% end new style

\begin{document}
\begin{tikzpicture}
\begin{loglogaxis}[
log basis x={2},
log basis y={10},
ytickten={4.6,4.8,...,7},
sci log y ticks, % use the defined style
]
\addplot coordinates {(2^8,1.585e7) (2^23,6.31e5)}; % dummy data
\end{loglogaxis}
\end{tikzpicture}
\end{document}


## Output

• Excellent answer! This is exactly what I was asking for. But as you rightly say, it does not look like a good idea to do this if I want to make the data dimension clear. Instead I will add extra y ticks and /pgfplots/log identify minor tick positions=true, and keep the basis constant. Someone else might find it useful though :) Commented Jul 25, 2014 at 17:25
• The clue that this is a logarithmic axis is already lost from the equally-spaced ticks, IMO. I came up with another approach that is both obviously logarithmic and very readable, see tex.stackexchange.com/q/208891/1750. Applies between 4 and 6 labelled ticks to the data in this question, which is fewer than default but seems reasonable. For large numbers such as this, it would probably be reasonable to have a coefficient of 10^6 taken out, ala scaled ticks. Final resulting tick labels: (0.5, 1, 2, 5, 10, 20) * 10^6 Commented Oct 24, 2014 at 21:56