4

What I want: highlight/pattern the left area under the plot between x=0 and x=value ( value is marked by the blue vertical line)

What I have: a plot as shown below with pattern in the wrong intersection part of the blue line and plot

What I tried: adapting the solution provided here, but I don't get why it is written the way it is. This at least explained that the values "L1--R2" are not arbitrarily selected in the first link but it does not give me better ideas for my code. Maybe you see the error that I made and can help me correct it. (and hopefully even explain/provide a link on the working principle of the intersections for the future)

So, at the moment it looks like the attached picture, but the patterned area is supposed to be left of the blue line.

\documentclass[10pt,a4paper]{article}
\usepackage[utf8]{inputenc}     
\usepackage[top=1.3in, bottom=1.2in, left=1.1in, right=0.9in]{geometry}
\usepackage{graphicx}
\usepackage{tikz} 
\usepackage{color}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.12}
\definecolor{darkblue}{RGB}{0,51,100}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}
\pgfplotstableread[col sep=space]{% 
5.92162500000000060E6   2.95192270864755280E-7
6.54625000000000060E6   2.98080690981653440E-7
7.17087499999999970E6   2.96534276326447840E-7
7.79549999999999970E6   3.02793732456258620E-7
8.42012500000000050E6   3.06886283233832160E-7
1.34171250000000030E7   3.28184774629206280E-7
1.90387500000000000E7   3.38239416667529100E-7
1.96633750000000030E7   3.36457487945737640E-7
2.02879999999999990E7   3.39779376603173590E-7
2.09126250000000000E7   3.41080958966797130E-7
2.27864999999999980E7   3.44990954160802940E-7
2.34111250000000040E7   3.39776166533671200E-7
8.02519999999999990E7   1.71932791566944100E-7
1.06486249999999980E8   4.59595284334464620E-9
1.07110875000000010E8   2.75798201098339790E-9
1.07735500000000010E8   -2.24378030944353400E-10
}\data

\begin{document}
\begin{tikzpicture}
        \begin{axis}[
            no markers,
            height=10cm,
            ymin=0,
            ymax=3.5*10^-7,
            enlarge y limits=upper,
            xmin=0,
            xmax={5*10^8},
            enlarge x limits=0.05,
            width=0.8\textwidth, 
            ]
        \addplot+[darkblue, name path=A] table [col sep=space] from \data;
        \draw[blue, dashed, name path=vline] (axis cs: 8.0251*10^7,\pgfkeysvalueof{/pgfplots/ymin}) -- (axis cs: 8.0251*10^7,\pgfkeysvalueof{/pgfplots/ymax}) node[anchor=west,rotate=90]{Some label};
        \path[name path=lower, intersection segments={of=A and vline, sequence= R1-- L2}
        ];
        \path[name path=axis] (0,0) -- (5*10^8,0);
        \addplot fill between[of=axis and lower, split, every segment no 0/.style={fill=none}, every segment no 1/.style={pattern=north east lines},
        ];
    \end{axis}
\end{tikzpicture}
\end{document}

This is what it looks like now, but the patterned section is supposed to be on the other side of the blue line.

  • Welcome to TeX SE! Please don't just load a snippet of your code, you should add a MWE. While trying to compile your code I got: color 'darkblue' undefined, so I created that on my own, 'name path' is undefined so I added the relevant library and now I have Could not read table file 'file.txt', which I can't recreate. In any case, you should always add a complete code so we don't have to start from scratch. – Alenanno Aug 22 '16 at 8:51
  • @Alenanno I added a MWE with a scaled-down dataset. (I did not do so from the beginning because the used measurement data are quite lengthy, and I kind of hoped that I made some obvious mistake that would be apparent on sight) – pogo-otter Aug 22 '16 at 9:25
  • No problem. Thanks for uploading the question. – Alenanno Aug 22 '16 at 9:38
3

There is a similar way to do this which involves some changes in your code:

  1. The x axis can be named in the options without the need of an external path using x axis line style={name path=axis}.
  2. There's no need for the definition of your lower path.
  3. The vertical limit has been assigned to a \newcommand. This way we can just use the variable where we need it and we only need to change it in one place for the entire graph. Of course, this makes it easier to be used in the soft clip for the fill as well. It's not necessary, but I think it looks neater.
  4. The plot for filling is slightly different: I'm not using the odd/even segment solution, rather just filling between the two paths and then using the domain to apply a soft clip.

Output

enter image description here

Code

\documentclass[margin=10pt]{standalone}
\usepackage{pgfplots,pgfplotstable}

\pgfplotsset{compat=1.13}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{patterns}

\definecolor{darkblue}{RGB}{0,51,100}

\pgfplotstableread[col sep=space]{% 
5.92162500000000060E6   2.95192270864755280E-7
6.54625000000000060E6   2.98080690981653440E-7
7.17087499999999970E6   2.96534276326447840E-7
7.79549999999999970E6   3.02793732456258620E-7
8.42012500000000050E6   3.06886283233832160E-7
1.34171250000000030E7   3.28184774629206280E-7
1.90387500000000000E7   3.38239416667529100E-7
1.96633750000000030E7   3.36457487945737640E-7
2.02879999999999990E7   3.39779376603173590E-7
2.09126250000000000E7   3.41080958966797130E-7
2.27864999999999980E7   3.44990954160802940E-7
2.34111250000000040E7   3.39776166533671200E-7
8.02519999999999990E7   1.71932791566944100E-7
1.06486249999999980E8   4.59595284334464620E-9
1.07110875000000010E8   2.75798201098339790E-9
1.07735500000000010E8   -2.24378030944353400E-10
}\data

\newcommand\myvline{8.0251*10^7}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
    no markers,
    height=10cm,
    ymin=0,
    ymax=3.5*10^-7,
    enlarge y limits=upper,
    xmin=0,
    xmax={5*10^8},
    enlarge x limits=0.05,
    width=0.8\textwidth, 
    x axis line style={name path=axis}
    ]

\addplot+[darkblue, name path=A] table [col sep=space] from \data;
\draw[blue, dashed, name path=vline] (axis cs: \myvline,\pgfkeysvalueof{/pgfplots/ymin}) -- (axis cs: \myvline,\pgfkeysvalueof{/pgfplots/ymax}) node[anchor=west,rotate=90]{Some label};

\addplot [
    fill=blue!10
    ]
    fill between[
        of=A and axis,
        soft clip={domain=0:\myvline},
];
\end{axis}
\end{tikzpicture}
\end{document}
  • Thank you very much, this is what i was looking for! You are right, this approach is more straight forward. I re-read the pgfplot manual - do I understand it correctly, that the soft clipping of an area X is meant in a way, that not area X is cut away but rather everything beside it (and the softclipping part therefore being something like an partial overlay over existing plot)? Do you perhaps know of further pages/pdf (beside PGFplot manual) with more examples? – pogo-otter Aug 22 '16 at 11:57

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.