1

I am trying to recreate the plot in the figure below. My initial idea would be to plot the four intervals of different scaling as separate plots, and align them seamlessly.

Is there a more elegant solution which allows for individual scaling of intervals on the x-axis?

enter image description here

EDIT: Based on the insights provided by @Rmano I was able (after much tweaking) to get the desired result. See code and output below.

 \pgfplotsset{
    x coord trafo/.code={
        \pgfmathparse{
            #1<=4?
            #1*50
            :%trekke fra 16
            (#1<30?
                #1*10+160
                :
                (#1<150?
                    #1*2+400
                    :
                    #1*0.5+625
                )
            )
        }
    },
    x coord inv trafo/.code={
        \pgfmathparse{
            #1<200?
                #1/50
                :
                (#1<460?
                    (#1-160)/10
                    :
                    (#1<640?
                        (#1-400)/2
                        :
                        (#1-625)/0.5
                    )
                )
        }
    }
 }

enter image description here

Eirik B
  • 85
  • 1
    In principle, there is a way to define generic axis transform in pgfplots (see https://tikz.dev/pgfplots/reference-transformations) but I never used it; you can combine that with the ternary ? ... : ... expression of pgmath https://tikz.dev/math-parsing#sec-94.2 and try. An example usage is also in https://tex.stackexchange.com/questions/106282/how-can-i-do-an-affine-coordinate-transformation-in-pgfplots – Rmano Oct 05 '23 at 09:19

1 Answers1

1

Found it! Here is the relevant part of the manual; I have an example in my disk, derived from Is it possible to alter the y-scaling for only part of a plot?:

%%% https://tex.stackexchange.com/questions/359878/is-it-possible-to-alter-the-y-scaling-for-only-part-of-a-plot
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}\pgfplotsset{compat=1.13}
\usetikzlibrary{arrows.meta,positioning,calc}
\begin{document}
\begin{tikzpicture}[fill=gray]

\pgfplotsset{ y coord trafo/.code={ \pgfmathparse{ #1>10? #1+20 : #1*3 } }, y coord inv trafo/.code={ \pgfmathparse{ #1>30? #1-20 : #1/3 } } } % thanks to Paul Gessler https://tex.stackexchange.com/a/235629/38080 %Prevent double labelling at origin \pgfplotsset{ignore zero/.style={% #1ticklabel={\ifdim\tick pt=0pt \else\pgfmathprintnumber{\tick}\fi} }}

\begin{axis}[ axis y line*=left, ymin=0, ymax=104, xmin=0, xmax=9.9, xlabel=units of time, ylabel=percentage, y=1.5cm/15, x=1.5cm, ignore zero=y, ]

\fill[gray!20] (0,0) rectangle (10,10);

\addplot[smooth,mark=*,blue] coordinates{ (0 , 100.000000000000) (1 , 21) (2 , 1.28) (3 , 0.21) (4 , 0.03) (5 , 0.004) (6 , 0.0005) (7 , 0.00005) (8 , 0.000007) (9 , 0.0000008) }; \addlegendentry{blue}

\addplot[smooth,mark=o,green] coordinates{ (0 , 100.000000000000) (1 , 2.004965950432) (2 , 0.050130282209) (3 , 0.001303231721) (4 , 0.000034413136) (5 , 0.000000916142) (6 , 0.000000024509) (7 , 0.000000000658) (8 , 0.000000000018) (9 , 0.000000000000)
}; \addlegendentry{green}

\addplot[smooth,mark=*,red] coordinates{ (0 , 100.000000000000) (1 , 30.969834976929) (2 , 11.504103027913) (3 , 4.422780528370) (4 , 1.725299638737) (5 , 0.678378118320) (6 , 0.268047163678) (7 , 0.106264332554) (8 , 0.042226956059) (9 , 0.016809562633)
}; \addlegendentry{red}

\addplot [purple, domain=0:8] {10*x}; \addlegendentry{straight}

\draw[ultra thick, white] (0,10) -- (10, 10);

\end{axis}

\end{tikzpicture} \end{document}

enter image description here

I think it could be applied to your case (using the corresponding x trafo... styles.

Rmano
  • 40,848
  • 3
  • 64
  • 125
  • I believe this a step in the right direction! I managed to create the first "break" at any of the three "breaks" in my example. I am struggling to create all the three "breaks" on the curve, however. I am attempting to do this with nested conditional sentences, but I can't seem to get it right ... – Eirik B Oct 06 '23 at 19:45
  • See my updated post where I after some tweaking managed to set the conditional sentences correctly (and their inverse transforms). Thank you for the help! – Eirik B Oct 07 '23 at 14:45
  • Hmm. The best way to do it here is to add your code as an answer, and then (you have to wait a couple of day, I think) move the accepted tick to your answer. Mine was just a suggestion that didn't fit in the comments... – Rmano Oct 08 '23 at 16:02
  • ...but please add your answer with a full, compilable code. – Rmano Oct 08 '23 at 16:05