1

I want to plot a dataset with pgfplots. In my dataset, 0 < x < 1 and everything interesting happens for values of x close to 1. In particular, the interesting points happen at halving intervals of x: 0.1, 0.15, 0.175, and so on.

So, I would like to do something like the opposite of a logscale plot: use a custom function to specify the progression along the x axis so that my interesting x coordinate are represented at regular intervals. Just like I would do with a logscale if the intervals were doubling.

I know this previous answer, but I was unable to find a suitable function for my case. I guess that I should use the x coord trafo/.code option, but which argument would be suitable for my case?

Any suggestion? Thank you in advance.

Ideally, I would like my x axis to appear like this:

=== 0 === 0.5 === 0.75 === 0.875 === etc.

for a simple dataset like this:

0.10  1
0.20  1
0.30  1
0.40  1
0.50  1
0.60  2
0.70  2
0.75  2
0.80  4
0.85  4
0.875 8
0.900 8

Currently this is my code, that does not obtain the intended result:

\documentclass{standalone}

\usepackage{standalone} \usepackage{pgfplots} \usepackage{graphicx} \usepackage{amsmath} \usepackage{xfp} \usepackage{ifthen}

\pgfplotstableread{ 0.10 1 0.20 1 0.30 1 0.40 1 0.50 1 0.60 2 0.70 2 0.75 2 0.80 4 0.85 4 0.875 8 0.900 8 }\dataset

\begin{document} \begin{tikzpicture} \begin{axis}[ xmin=0, xmax=1, scaled x ticks=false, x coord trafo/.code = {\pgfmathparse{\ifthenelse{#1==0}{1-(1/#1)}{0}}\pgfmathresult}, x coord inv trafo/.code = {\pgfmathparse{\ifthenelse{#1==0}{1-(1/#1) }{0}}\pgfmathresult}, scaled y ticks=false, ]

\addplot table [x index = 0 , y index = 1 , col sep=comma]\dataset;

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

ellerre
  • 11
  • 2
  • You can use parametric plots by defining x and y as functions of some other variable (like t). See https://tex.stackexchange.com/questions/280595/plotting-the-graph-for-expcos1-x/280607?r=SearchResults&s=5|10.6676#280607 for example. – John Kormylo Dec 17 '21 at 04:33
  • Looks like you already figured out the answer, the rest is a math question rather than a TeX question. ("which function maps 0.1 → 1, 0.15 → 2, 0.175 → 3, etc., and what's its inverse function?") However... – user202729 Dec 17 '21 at 06:06
  • @JohnKormylo OP in this case want to change labels on the x axis, not that one. – user202729 Dec 17 '21 at 06:07
  • ... first, are you sure that you're asking the correct question? The sequence (0.1, 0.15, 0.175, ...) appears to tend to 2. – user202729 Dec 17 '21 at 06:08
  • @user202729 Thank you for the quick reply. Indeed, my example was wrong. I updated it and the desired axis, and I added a sample of the code I'm trying to use. Still no success, though... – ellerre Dec 17 '21 at 23:18
  • It seems that your math is wrong... or you're not understanding correctly what the option do? – user202729 Dec 18 '21 at 01:12
  • It may be either ways. About the option, there is very little documentation available, even on the manual. I've not found any useful example of this kind on the whole web. – ellerre Dec 19 '21 at 18:41
  • (by the way if you don't ping I won't get notified.) Even on the manual? I'm not sure what you don't understand, after understanding it you should write an answer on the other question to make it easier for the other people who did not understand it the same way as you did. – user202729 Dec 20 '21 at 03:15
  • Okay, so x coord trafo transform the data X coordinate (provide by your file/table) to the screen X coordinate (distance on screen/paper etc.), and x coord inv trafo transform the screen X coordinate to the label X coordinate (the numbers on the labels). Is that clear? – user202729 Dec 20 '21 at 03:16

0 Answers0