1

The user esdd has posted a nice approach on how to increase point density for a certain range of data points while the remaining plot keeps low point density by using x filter.


Minimum Working Example (MWE):

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

\begin{filecontents}{data.csv}
    Time;Value
    0.000;24.3
    0.008;67.1
    0.017;74.7
    0.025;71.3
    0.033;66.5
    0.042;61.8
    0.050;57.7
    0.058;54.6
    0.067;52.2
    0.075;49.7
    0.083;47.8
    0.092;46.3
    0.100;45.3
    0.108;44.0
    0.117;43.0
    0.125;42.3
    0.133;41.8
    0.142;41.2
    0.150;40.7
    0.158;40.3
    0.167;39.8
    0.175;39.7
    0.183;39.3
    0.192;39.0
    0.200;38.8
    0.208;38.5
    0.217;38.5
    0.225;38.2
    0.233;38.1
    0.242;37.9
    0.250;37.8
    0.258;37.7
    0.267;37.5
    0.275;37.3
    0.283;37.0
    0.292;37.0
    0.300;37.0
    0.308;36.8
    0.317;36.5
    0.325;36.6
    0.333;36.3
    0.342;36.5
    0.350;36.2
    0.358;36.2
    0.367;36.1
    0.375;36.0
    0.383;35.9
    0.392;35.9
    0.400;35.7
    0.408;35.5
    0.417;35.4
    0.425;35.4
    0.433;35.3
    0.442;35.2
    0.450;35.1
    0.458;34.9
    0.467;35.0
    0.475;34.9
    0.483;34.9
    0.492;34.8
    0.500;34.7
    0.508;34.5
    0.517;34.3
    0.525;34.4
    0.533;34.5
    0.542;34.3
    0.550;34.2
    0.558;34.2
    0.567;34.1
    0.575;34.1
    0.583;33.9
    0.592;33.9
    0.600;33.7
    0.608;33.8
    0.617;33.8
    0.625;33.7
    0.633;33.6
    0.642;33.5
    0.650;33.5
    0.658;33.5
    0.667;33.3
    0.675;33.3
    0.683;33.2
    0.692;33.2
    0.700;33.1
    0.708;33.1
    0.717;33.0
    0.725;33.0
    0.733;32.9
    0.742;32.9
    0.750;32.8
    0.758;32.7
    0.767;32.8
    0.775;32.6
    0.783;32.6
    0.792;32.5
    0.800;32.5
    0.808;32.4
    0.817;32.4
    0.825;32.4
    0.833;32.3
    0.842;32.1
    0.850;32.2
    0.858;32.1
    0.867;32.1
    0.875;32.0
    0.883;32.0
    0.892;32.0
    0.900;32.0
    0.908;32.0
    0.917;31.8
    0.925;31.8
    0.933;31.8
    0.942;31.7
    0.950;31.7
    0.958;31.6
    0.967;31.6
    0.975;31.7
    0.983;31.6
    0.992;31.6
    1.000;31.5
\end{filecontents}

\begin{document}
    \begin{tikzpicture}
        \begin{axis}
            [x filter/.code={\pgfmathparse{#1>0.3 && mod(\coordindex,10)!=0 ? nan :#1}}]
            \addplot table[col sep = semicolon,x=Time,y=Value] {data.csv};
        \end{axis}
    \end{tikzpicture}%
\end{document}

Screenshot of the result:

Screenshot of the result


Description of the issue:

Assumed I have a huge amount of data points (e.g. from measuring several values with an interval of 30 seconds for a time span of 7 days = 20160 data sets). Only the points with values higher than 40 are relevant.

Would it be possible to apply the following properties for the plot to decrease its file size:

  • Set each nth point = {1} for all points if point value is higher than 40
  • Set each nth point = {30} for all points if point value is lower than 40

Or, tried to explain in programmers language:

IF point-value > 40, THEN each nth point = {1}; ELSE each nth point = {30};


With this I try to reduce the plot file size to make compiling possible at all. Furthermore, the basic "data noise" without importance is displayed in less precision.

1

I am wondering why you are using an x filter rather than an y filter if you want to filter out points that are below a certain value. If I set an y filter, I get

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{filecontents}

\begin{filecontents}{data.csv}
    Time;Value
    0.000;24.3
    0.008;67.1
    0.017;74.7
    0.025;71.3
    0.033;66.5
    0.042;61.8
    0.050;57.7
    0.058;54.6
    0.067;52.2
    0.075;49.7
    0.083;47.8
    0.092;46.3
    0.100;45.3
    0.108;44.0
    0.117;43.0
    0.125;42.3
    0.133;41.8
    0.142;41.2
    0.150;40.7
    0.158;40.3
    0.167;39.8
    0.175;39.7
    0.183;39.3
    0.192;39.0
    0.200;38.8
    0.208;38.5
    0.217;38.5
    0.225;38.2
    0.233;38.1
    0.242;37.9
    0.250;37.8
    0.258;37.7
    0.267;37.5
    0.275;37.3
    0.283;37.0
    0.292;37.0
    0.300;37.0
    0.308;36.8
    0.317;36.5
    0.325;36.6
    0.333;36.3
    0.342;36.5
    0.350;36.2
    0.358;36.2
    0.367;36.1
    0.375;36.0
    0.383;35.9
    0.392;35.9
    0.400;35.7
    0.408;35.5
    0.417;35.4
    0.425;35.4
    0.433;35.3
    0.442;35.2
    0.450;35.1
    0.458;34.9
    0.467;35.0
    0.475;34.9
    0.483;34.9
    0.492;34.8
    0.500;34.7
    0.508;34.5
    0.517;34.3
    0.525;34.4
    0.533;34.5
    0.542;34.3
    0.550;34.2
    0.558;34.2
    0.567;34.1
    0.575;34.1
    0.583;33.9
    0.592;33.9
    0.600;33.7
    0.608;33.8
    0.617;33.8
    0.625;33.7
    0.633;33.6
    0.642;33.5
    0.650;33.5
    0.658;33.5
    0.667;33.3
    0.675;33.3
    0.683;33.2
    0.692;33.2
    0.700;33.1
    0.708;33.1
    0.717;33.0
    0.725;33.0
    0.733;32.9
    0.742;32.9
    0.750;32.8
    0.758;32.7
    0.767;32.8
    0.775;32.6
    0.783;32.6
    0.792;32.5
    0.800;32.5
    0.808;32.4
    0.817;32.4
    0.825;32.4
    0.833;32.3
    0.842;32.1
    0.850;32.2
    0.858;32.1
    0.867;32.1
    0.875;32.0
    0.883;32.0
    0.892;32.0
    0.900;32.0
    0.908;32.0
    0.917;31.8
    0.925;31.8
    0.933;31.8
    0.942;31.7
    0.950;31.7
    0.958;31.6
    0.967;31.6
    0.975;31.7
    0.983;31.6
    0.992;31.6
    1.000;31.5
\end{filecontents}

\begin{document}
    \begin{tikzpicture}
        \begin{axis}[
        y filter/.expression={(y < 45 && mod(\coordindex,10) >0)? nan : y}]
            \addplot table[col sep = semicolon,x=Time,y=Value] {data.csv};
        \end{axis}
    \end{tikzpicture}%
\end{document}

enter image description here

  • Once again, thank you very much for your help marmot! :-) I didn't know that there is also a y filter available. Just one last question: In case my table has more than only two columns, how can I specify which column should be chosen as the key-column for the y filter? Or does y filter select exactly the y value-column that you selected within addplot? – Dave Apr 20 at 18:29
  • 1
    @Dave You're welcome! You are saying table[col sep = semicolon,x=Time,y=Value] so y comes from the column Value. Notice that you can use visualization depends on in order to also access data from other columns, but so far I have never used this in combination with filters. – marmot Apr 20 at 18:32
  • Awesome! Thank you very much and happy easter! :-) – Dave Apr 20 at 18:33
  • Just out of curiousity: Does it make sense at all to decrease the amount of points with the aim to reduce LaTeX memory usage (to be able compile larger plots)? Or doesn't the amount of points have any effect on LaTeX memory usage? – Dave Apr 20 at 19:51
  • @Dave I do not know that, sorry. – marmot Apr 20 at 19:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.