我如何创建反向主题,就像在黑纸上绘画一样?

我如何创建反向主题,就像在黑纸上绘画一样?

在 Manim(用于制作动画的 3b1b 编程语言)中,我们可以得到一些背景为黑色的精美动画,我们可以在 LaTeX 中使用吗Tikz

这是一个例子:我想绘制这个图形,但背景为黑色。

\begin{tikzpicture}[
point/.style={circle,fill,inner sep=1.3pt}]
\draw[thin, dashed, black!50!] (0,0) -- (8,0);
\begin{scope}[rotate around={15:(8:0)}]
\draw[thin, black] (0,0) -- (8,0);
\draw[fill, gray!40] (2,0) rectangle (4,1);
\draw[black] (2,0) rectangle (4,1);
\draw (3,0.5) node{$\bullet$}node[above,right]{$G$};
\draw[dashed, black] (3,0) -- (3,3);
\draw[thick, black, ->] (3,0) -- (2.4,1.5) node[above]{$\vec{R}$};

\coordinate(y) at (3,0);
\coordinate(x) at (3,1.5);
\coordinate(z) at (2.6,1);
\pic [draw=black!15!black,text=black,angle radius=9mm,"$\varphi$",angle eccentricity=1.3, ->]{angle = x--y--z};
\end{scope}
 \draw[thick, black,->] (2.86,1)--(2.86,0) node[above,right]{$\vec{P}$};
\coordinate(o) at (0,0);
\coordinate(i) at (2,0.5);
\coordinate(j) at (2,0);
\pic [draw=black!15!black,text=black,angle radius=9mm,"$\alpha$",angle eccentricity=1.3, ->]{angle = j--o--i};

       \end{tikzpicture}

在此处输入图片描述

或者绘制一个函数作为 Gamma 函数的示例: 在此处输入图片描述

以下是答案中的代码:

\begin{tikzpicture}[]

\begin{axis}[
xmin = -4.9, xmax = 5.1, 
%ymin = -3.5, ymax = 3.5,  
restrict y to domain=-6:6,
axis lines = middle,
axis line style={-latex},  
xlabel={$x$}, 
ylabel={$y$},
%enlarge x limits={upper={val=0.2}},
enlarge y limits=0.05,
x label style={at={(ticklabel* cs:1.00)}, inner sep=5pt, anchor=north},
y label style={at={(ticklabel* cs:1.00)}, inner sep=2pt, anchor=south east},
]

\addplot[color=red, samples=222, smooth, 
domain = 0:5] gnuplot{gamma(x)};

\foreach[evaluate={\N=\n-1}] \n in {0,...,-5}{%
\addplot[color=red, samples=555, smooth,  
domain = \n:\N] gnuplot{gamma(x)};
%
\addplot [domain=-6:6, samples=2, densely dashed, thin] (\N, x);
}%
\end{axis}
\end{tikzpicture}

有什么方法可以让这些图形具有黑色背景的“黑暗主题”吗?

答案1

tikzpicture一般来说,简单的方法是通过库添加背景backgrounds,对于您的第一个例子(我无法让它\pic工作,但您会弄清楚的),可以是:

\documentclass[tikz]{standalone}

\usetikzlibrary{angles,backgrounds}

\begin{document}
\begin{tikzpicture}[
point/.style={circle,fill,inner sep=1.3pt},background rectangle/.style={fill=black}, show background rectangle]
\draw[thin, dashed, black!50!] (0,0) -- (8,0);
\begin{scope}[rotate around={15:(8:0)}]
\draw[thin, white] (0,0) -- (8,0);
\draw[fill, gray!40] (2,0) rectangle (4,1);
\draw[white] (2,0) rectangle (4,1);
\draw[white] (3,0.5) node{$\bullet$}node[above,right]{$G$};
\draw[dashed, white] (3,0) -- (3,3);
\draw[thick, white, ->] (3,0) -- (2.4,1.5) node[above]{$\vec{R}$};

\coordinate(y) at (3,0);
\coordinate(x) at (3,1.5);
\coordinate(z) at (2.6,1);
%\pic [draw=black!15!black,text=black,angle radius=9mm,"$\varphi$",angle eccentricity=1.3, ->]{angle = x--y--z};
\end{scope}
\draw[thick, white,->] (2.86,1)--(2.86,0) node[above,right]{$\vec{P}$};
\coordinate(o) at (0,0);
\coordinate(i) at (2,0.5);
\coordinate(j) at (2,0);
%\pic [draw=black!15!black,text=black,angle radius=9mm,"$\alpha$",angle eccentricity=1.3, ->]{angle = j--o--i};

\end{tikzpicture}
\end{document}

结果是:

在此处输入图片描述

相关内容