2

I'm trying to improve that figure:

tikzpicture

\documentclass{standalone}
\begin{document}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{tikzpicture}
  \begin{axis} [axis lines=center, height=46mm, width=120mm, ymin = 0.8499]
    \addplot [domain=0:1, samples=3333, thick] { 1-(1-x)^floor(2/x) };
  \end{axis}
\end{tikzpicture}
\end{document}

I'd like to

  • make the curve discontinuous: the current down-going lines are pure artifact
  • avoid the non-existing transititon there is near x=0.1
  • if possible, make it faster. I'm ready to make a black triangle for x<1/30 or so.

I think an explicit loop drawing multiple curves in range ]1/(n+1),1/n[ is the way to go; but how?

1
  • 1
    Remember to add compilable code starting with \documentclass.... Commented Jun 19, 2021 at 13:45

2 Answers 2

3

Perhaps something like this? It's not very fast, but you can reduce the samples or the \foreach limit of 500.

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

\begin{document}
\begin{tikzpicture}[line cap=round]
\begin{axis} [axis lines=center, height=45mm, width=120mm, xmin=0, ymin=0.8499]
  \foreach\i in {2,...,500}
  {%
    \addplot[domain={2.001/(\i+1)}:{2/\i}, samples=11,smooth] {1-(1-\x)^floor(2/\x)};
  }
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

2
  • 1
    Nice. As it is mostly lines, going from 11 samples down to 5 with smooth only changes the plot imperceptibly. Commented Jun 19, 2021 at 13:56
  • Excellent. I made it slightly faster with {\addplot[domain={2.0005/(\i+1)}:{1.9995/\i}, samples=2+floor(20/\i),smooth,thick] {1-(1-\x)^floor(2/\x)}; }, and I'll bump the range to 1000 in the final rendering. Thanks!
    – fgrieu
    Commented Jun 19, 2021 at 14:22
3

This is just to show that it is possible to introduce jumps in a single plot:

\documentclass[tikz, border=1 cm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis} [axis lines=center, height=46mm, width=120mm, ymin = 0.8499]
    \addplot [
    domain=0:1,
    samples=3333,
    thick, 
    unbounded coords=jump, line join=bevel,
    x filter/.expression={
        x>0.08 && floor(2/x)+0.01/x>2/x ? nan : x}
                ] { 1-(1-x)^floor(2/x) };   
  \end{axis}
\end{tikzpicture}
\end{document}

Graph

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .