tikz:用角度填充阴影颜色

发布于 2025-02-11 18:45:24 字数 1144 浏览 2 评论 0原文

目标:画一个半圆,并用线梯度填充,根据角度变化。例如,角度从θ= 0到θ=π,可以预期填充色调从红色到蓝色。

在tikz手册中( https://tikz.dev/library-shadings ),阴影模式没有我在以下方面的需求:

  1. 选项shading =色轮似乎仅适用于圆而不是半圆。

  2. 选项shading =色轮在原点处呈现扭曲的颜色,而shading =色轮白色中心填充了原点的白色区域。

  3. 颜色whell似乎并不是真正的线路分级。

因此,有什么方法可以通过角度填充线梯度填充理想的半圆?


可以看到一个类似的示例在这里,但是需要一些更改:

  1. 可以预期。是半圆而不是象限。

  2. 填充的颜色优于按角度(或其结合角度)为渐变。


我尝试了以下代码,但是梯度模式似乎并不十分明显,而起源很棘手。

\documentclass[tikz, margin=5pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{shadings}

\begin{document}

\begin{tikzpicture}
    \clip (0, 0) -- (1, 0) arc [start angle=0, end angle=180, radius=1cm] -- cycle ;
    \shade[shading=color wheel, shading angle=-60] (0, 0) circle (1cm) ;
\end{tikzpicture}

\end{document}

Goal: Draw a semi-circle and fill it with line-gradient color that changes according to angle. For example, with angle from θ=0 to θ=π, it is expected that the filling color shades from red to blue.

In tikz manual (https://tikz.dev/library-shadings), the shading pattern does not statisfy my need in the following aspects:

  1. The option shading = color wheel seems to only applicable to a circle rather than semi-circle.

  2. The option shading = color wheel renders a distorted color at the origin, while shading=color wheel white center fills a white region at the origin.

  3. The color whell seems not really line-gradient.

So, is there any way to make an ideal semi-circle with line-gradient color filling by angle?


A similar example can be seen here, but some changes are needed:

  1. It is expected to be semi-circle rather than a quadrant.

  2. The filled color is prefered to be gradient according the angle(or its consine).


I tried the following codes, but the gradient pattern seems not quite obvious, and the origin is screwy.

\documentclass[tikz, margin=5pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{shadings}

\begin{document}

\begin{tikzpicture}
    \clip (0, 0) -- (1, 0) arc [start angle=0, end angle=180, radius=1cm] -- cycle ;
    \shade[shading=color wheel, shading angle=-60] (0, 0) circle (1cm) ;
\end{tikzpicture}

\end{document}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

落叶缤纷 2025-02-18 18:45:24

我建议使用pgfplots,然后您对颜色尺度的控制最多:

\documentclass[tikz, margin=5pt]{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    axis equal=true,
    hide axis,     
    domain=0:180,
    domain y=0:1,
    view={0}{90},
    shader=interp,
    colormap={redblue}{
        color=(red)  color=(blue)
    },
    data cs=polar,
]
    \addplot3 [surf] {x};
\end{axis}
\end{tikzpicture}

\end{document}

“在此处输入图像说明”

I suggest to use pgfplots, then you have the most control over the colour scale:

\documentclass[tikz, margin=5pt]{standalone}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    axis equal=true,
    hide axis,     
    domain=0:180,
    domain y=0:1,
    view={0}{90},
    shader=interp,
    colormap={redblue}{
        color=(red)  color=(blue)
    },
    data cs=polar,
]
    \addplot3 [surf] {x};
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文