我的图表中有一个特定的区域,我想让它保持绿色。我希望它在其周围逐渐变成红色。到目前为止,我只发现在我绘制的对象内部从红色逐渐变成绿色的可能性。我希望淡入淡出从我用坐标设置的边界开始。现在它看起来像这样:
\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}
非常感谢你的帮助]1
答案1
欢迎!这里有一个东西可以使任何路径的边界变得模糊。这是通过应用postaction
具有不同线宽和不透明度的多个 s 来实现的。后期操作的数量为n
,模糊半径r
为
\path[green,fuzzy={n=40,r=20pt}]
plot[smooth cycle] coordinates{(90,1) (140,1) (140,1.50) (100,1.5) (80,1.25)};
代码:
\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}
人们还可以用同样的策略来设计颜色转变。
\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}