3

I would like to plot data with pgfplots that has two interessting x-ranges:

  1. 0 <= x <= 300
  2. limit for x -> inf (or some defined upper boundary)

So, to show both ranges appropriately, my idea is to have a single plot which has a linear scale from x = 0 up to x = 300 and a logarithmic scale for the x-axis above. Additionally, since the first range (linear scale) is more important than the second one (logarithmic scale), it should have a greater width. Let the width-ratio be 3:1.

Here a MWE with a sample of the data to plot. It produces two plots, one with linear scale and another one with logarithmic scale:

\documentclass[crop, tikz]{standalone}
\usepackage{pgfplots}
\usepackage{filecontents}

\begin{filecontents}{sample.csv} 1, 2.42 100, 2.54 200, 2.66 300, 2.75 400, 2.81 1000, 2.94 2000, 2.97 3000, 2.98 5000, 2.99 10000, 3.00 \end{filecontents}

\begin{document} \begin{tikzpicture} \begin{axis}[ xlabel=x, ylabel=y, xmin = 0, xmax = 10000, grid = both], \addplot[line width=1pt,solid,color=cyan, solid] table[col sep=comma]{sample.csv}; \end{axis} \end{tikzpicture} \begin{tikzpicture} \begin{semilogxaxis}[ xlabel=x, ylabel=y, xmin = 0, xmax = 10000, grid = both], \addplot[line width=1pt,solid,color=cyan, solid] table[col sep=comma]{sample.csv}; \end{semilogxaxis} \end{tikzpicture} \end{document}

MWE output

jonas
  • 71
  • 1
    This sounds like a "symlog" axis. For that there are related questions here like https://tex.stackexchange.com/q/348998/95441. And for the record: There is also a feature request for that kind of axis already in the tracker (https://github.com/pgf-tikz/pgfplots/issues/281). – Stefan Pinnow Aug 03 '20 at 15:04

1 Answers1

4

It feels a bit nasty but with groupplots two plots can be aligned side-by-side with different scales. Using the option horizontal sep = 0 while taking care for the y-axis with axis y line* = left / axis y line* = right leads to a smooth transition to the second plot.

\documentclass[crop, tikz]{standalone}
\usepackage{pgfplots}
\usepackage{filecontents}
\usepgfplotslibrary{groupplots}

\begin{filecontents}{sample.csv} 1, 2.42 100, 2.54 200, 2.66 300, 2.75 400, 2.81 1000, 2.94 2000, 2.97 3000, 2.98 5000, 2.99 10000, 3.00 \end{filecontents}

\begin{document} \begin{tikzpicture} \begin{groupplot}[group style = { group size = 2 by 1, horizontal sep = 0}, width = \linewidth, tick label style={font=\footnotesize}, typeset ticklabels with strut, enlarge x limits=false] \nextgroupplot[ xmin = 0, xmax = 300, ymin = 2.4, ymax = 3.1, width = 0.75\linewidth, height = 0.75\linewidth, axis y line* = left, grid = both] \addplot[line width = 1pt, solid, color = cyan] table[col sep = comma] {sample.csv}; \nextgroupplot[ xmin = 300, xmax = 10000, ymin = 2.4, ymax = 3.1, width = 0.25\linewidth, height = 0.75\linewidth, xmode = log, axis y line* = right, grid = both, xtick = {1000, 10000}, yticklabels = {,,}] \addplot[line width = 1pt, solid, color = cyan] table[col sep = comma] {sample.csv}; \end{groupplot} \end{tikzpicture} \end{document}

enter image description here

jonas
  • 71