![使用中间色创建圆形阴影](https://linux22.com/image/259370/%E4%BD%BF%E7%94%A8%E4%B8%AD%E9%97%B4%E8%89%B2%E5%88%9B%E5%BB%BA%E5%9C%86%E5%BD%A2%E9%98%B4%E5%BD%B1.png)
我需要画一个圆圈来表示密度,该密度在半径达到某个值之前是恒定的,然后开始下降。我的意思是这样的:
\documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\shade [shading=radial,inner color=black] (0,4) circle (2cm);
\draw [fill=lightgray] (0,4) circle (1cm);
\draw[->] [very thick] (0,0) -> (0,2);
\draw[->] [very thick] (0,0) -> (3,0);
\draw [dotted] (0,2) -> (0,4);
\draw [dotted] (1,0) -> (1,4);
\draw [dotted] (2,0) -> (2,4);
\draw [thick] (0,.25) -- (1,.25) -- (1,1.35) --
(1.25,1.35) .. controls (1.625,1.35)
and (1.625,0) .. (2,0);
\draw (-.2,1.7) node {$\rho$};
\draw (1,-.2) node {$R_{in}$};
\draw (2,-.2) node {$R_{out}$};
\draw (3.1,-.2) node {$R$};
\end{tikzpicture}
\end{document}
由此产生了如下结果:
我想要的是这个:
注意圆圈的线条与阴影的起始颜色相匹配。我以为可以通过为阴影设置“中间颜色”来实现这一点,但这个选项似乎不存在。
理想情况下,阴影应该与第一个图底部的情节紧密相关,但我认为这是一个额外的好处。
答案1
您可以使用这个答案并根据您的情况采用:
\documentclass[12pt]{article}
\usepackage{tikz}
%Code from Paul Gabroit -- https://tex.stackexchange.com/a/82503/11232
%%%%%%%%%%%%%%%%%%%%%%%%%
\tikzset{
ring shading/.code args={from #1 at #2 to #3 at #4}{
\def\colin{#1}
\def\radin{#2}
\def\colout{#3}
\def\radout{#4}
\pgfmathsetmacro{\proportion}{\radin/\radout}
\pgfmathsetmacro{\outer}{.8818cm}
\pgfmathsetmacro{\inner}{.8818cm*\proportion}
\pgfmathsetmacro{\innerlow}{\inner-0.01pt}
\pgfdeclareradialshading{ring}{\pgfpoint{0cm}{0cm}}%
{
color(0pt)=(white);
color(\innerlow)=(white);
color(\inner)=(#1);
color(\outer)=(#3)
}
\pgfkeysalso{/tikz/shading=ring}
},
}
%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{tikzpicture}
\shade[even odd rule,ring shading={from black at 1 to white at 2}]
(0,4) circle (2) ;
%\shade[shading=radial,inner color=black](0,4) circle (2cm);
\draw [fill=lightgray] (0,4) circle (1cm);
\draw[->] [very thick] (0,0) -> (0,2);
\draw[->] [very thick] (0,0) -> (3,0);
\draw [dotted] (0,2) -> (0,4);
\draw [dotted] (1,0) -> (1,4);
\draw [dotted] (2,0) -> (2,4);
\draw [thick] (0,.25) -- (1,.25) -- (1,1.35) --
(1.25,1.35) .. controls (1.625,1.35)
and (1.625,0) .. (2,0);
\draw (-.2,1.7) node {$\rho$};
\draw (1,-.2) node {$R_{in}$};
\draw (2,-.2) node {$R_{out}$};
\draw (3.1,-.2) node {$R$};
\end{tikzpicture}
\end{document}