2

I have a specific field in my diagramm, whitch I would like to leave green. Around that I would like it to fade into red. By now I only found the possibility to fade inside my drawn object from red to green. I would like the fading to start just at the boundaries I set with my coordinates. By now it looks like this:

\documentclass[a4paper,oneside,11pt,ngerman]{scrbook}
\usepackage[pdftex] {graphicx}
\usepackage{pdfpages}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{tikzit}
\usetikzlibrary{arrows,shapes,positioning,shadows,trees}
%
\begin{document}
%
\begin{tikzpicture}
        \begin{axis}[
            width=10cm,
            height=7cm,
            scale only axis,
            xmin=50,
            xmax=160,
            xtick={60, 80, ..., 150},
            xlabel={test},
            xmajorgrids,
            ymin=0.75,
            ymax=1.75,
            ytick={1, 1.25,..., 1.75},
            ylabel={test},
            yticklabel style={/pgf/number format/precision=3},
            ymajorgrids
]
%
    \draw[inner color=green, outer color=red]
        plot[smooth cycle] coordinates{(90,1) (140,1) (140,1.50) (100,1.5) (80,1.25)};
%
    \end{axis}
\end{tikzpicture}
%
\end{document}

Thank you very much for helping me![test with fading inside of the drawn path]1

3

Welcome! Here is something that makes the boundary of any path fuzzy. This is achieved by applying multiple postactions with different line widths and opacities. The number of post actions is n and the radius of fuzziness is r in

\path[green,fuzzy={n=40,r=20pt}]
        plot[smooth cycle] coordinates{(90,1) (140,1) (140,1.50) (100,1.5) (80,1.25)};

Code:

\documentclass[a4paper,oneside,11pt,ngerman]{scrbook}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\newcounter{fuzzy}
\tikzset{fuzzy/.code={\tikzset{/tikz/fuzziness/.cd,#1}%
\edef\mystyle{}\edef\fuzzynum{0}%
\loop
\ifnum\fuzzynum<\pgfkeysvalueof{/tikz/fuzziness/n}%
\edef\fuzzynum{\the\numexpr\fuzzynum+1}%
\pgfmathsetmacro{\myopa}{\fuzzynum/\pgfkeysvalueof{/tikz/fuzziness/n}}%
\pgfmathsetmacro{\mylw}{2*\pgfkeysvalueof{/tikz/fuzziness/r}*(1-\myopa)}%
\edef\mystyle{\mystyle,postaction={fill,draw,line width=\mylw pt,opacity=\myopa}}%
\repeat
\tikzset{postaction/.expanded=\mystyle}
},
fuzziness/.cd,n/.initial=10,r/.initial=10pt}
\begin{document}
%
\begin{tikzpicture}
        \begin{axis}[
            width=10cm,
            height=7cm,
            scale only axis,
            xmin=50,
            xmax=175,
            xtick={60, 80, ..., 150},
            xlabel={test},
            xmajorgrids,
            ymin=0.75,
            ymax=1.75,
            ytick={1, 1.25,..., 1.75},
            ylabel={test},
            yticklabel style={/pgf/number format/precision=3},
            ymajorgrids,
            axis background/.style={fill=red},
]
    \path[green,fuzzy={n=40,r=20pt}]
        plot[smooth cycle] coordinates{(90,1) (140,1) (140,1.50) (100,1.5) (80,1.25)};
    \end{axis}
\end{tikzpicture}
%
\end{document}

enter image description here

One can also engineer color transitions with the same strategy.

\documentclass[a4paper,oneside,11pt,ngerman]{scrbook}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\newcounter{fuzzy}
\tikzset{color transition/.code={\tikzset{/tikz/color transition/.cd,#1}%
\edef\mystyle{}\edef\fuzzynum{0}%
\loop
\ifnum\fuzzynum<\pgfkeysvalueof{/tikz/color transition/n}%
\edef\fuzzynum{\the\numexpr\fuzzynum+1}%
\pgfmathtruncatemacro{\myopa}{100*\fuzzynum/\pgfkeysvalueof{/tikz/color transition/n}}%
\pgfmathsetmacro{\mylw}{2*\pgfkeysvalueof{/tikz/color transition/r}*(1-\myopa/100)}%
\edef\mycolor{\pgfkeysvalueof{/tikz/color transition/inner}!\myopa!\pgfkeysvalueof{/tikz/color transition/outer}}%
\edef\mystyle{\mystyle,postaction={fill=\mycolor,draw=\mycolor,draw,line width=\mylw pt}}%
\repeat
\tikzset{postaction/.expanded=\mystyle}
},
color transition/.cd,n/.initial=10,r/.initial=10pt,inner/.initial=black,outer/.initial=white}
\begin{document}
%
\begin{tikzpicture}
        \begin{axis}[
            width=10cm,
            height=7cm,
            scale only axis,
            xmin=50,
            xmax=175,
            xtick={60, 80, ..., 150},
            xlabel={test},
            xmajorgrids,
            ymin=0.75,
            ymax=1.75,
            ytick={1, 1.25,..., 1.75},
            ylabel={test},
            yticklabel style={/pgf/number format/precision=3},
            ymajorgrids,
            axis background/.style={fill=red},
]
    \path[green,color transition={n=40,r=20pt,inner=green,outer=red}]
        plot[smooth cycle] coordinates{(90,1) (140,1) (140,1.50) (100,1.5) (80,1.25)};
    \end{axis}
\end{tikzpicture}
%
\end{document}

enter image description here

| improve this answer | |
  • 1
    Thank you very much (for the solution and the welcoming)! Unfortunatly, thats not quite what I am looking for... I want to express a specific field of parameters that are suitable for a process with the green area. Around that area in a certain range the parameters are still somewhat suitable (whitch I would like to express with the color fading). As far as I understand your solution gives radial shadings independent of the path I have drawn. – Pausch Feb 29 at 20:28
  • 1
    @Pausch I added something that makes the boundary fuzzy, which is effectively some path fading. One can easily rewrite this to yield a color transition, it needed. – user194703 Feb 29 at 20:43
  • Thank you so much, thats exactly what I was looking for! – Pausch Feb 29 at 20:47

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.