PGFPlots / TikzPicture 两个具有变化半径的对应图

PGFPlots / TikzPicture 两个具有变化半径的对应图

我完全不知道如何在 Latex 中实现以下两个图表。我用 tikzpicture 做了很多工作,但我的项目都没有包含类似的东西。

右图表示左图中“圆”的半径。右图显示两个或多个圆,半径每度变化一次。所以它不是一个“偶数圆”。

两张图 Tikzpgf 手册:https://www.bu.edu/math/files/2013/08/tikzpgfmanual.pdf

问题:

  1. 如何绘制这些“圆圈”
  2. 如何将两张图关联起来?

我感谢任何类型的帮助!


来自巴伐利亚州帕斯卡的问候

答案1

正如 John Kormylo 在评论中提到的,您可以使用参数图来pgfplots实现这一点。定义一个适当的函数,将半径描述为角度的函数,然后使用

\addplot (
          {<function that describes the x-component>},
          {<function that describes the y-component>}
         );

这里,因为我为 r(θ) 定义了函数,所以正常的参数化是 x = r * cos(θ) 和 y = r * sin(θ)。请注意,三角函数使用pgf度数,因此如果输入弧度,则必须将其转换为度数。

对于第二个图,只需使用\addplot {r(x)};,其中r是之前定义的某个函数。

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{groupplots}
\usetikzlibrary{decorations.markings}

\tikzset{
   % define a style that lets you place an arrow on a path
   arrow on path/.style={
     decoration={
        markings,
        mark=at position #1 with \arrow{>}
        },
     postaction=decorate
  },
  % set the default position of the arrow head to 10% along the path
  arrow on path/.default=0.1
}

\begin{document}
\begin{tikzpicture}[
% define the functions that give the relationship between
% the angle and the radius here
% pgf trig functions assume degrees by default, hence the
% conversion to degrees with deg(..)
declare function={
  r0(\x) = 0.1 - 0.01*\x;
  r1(\x) = 0.5 + 0.07*\x + 0.08*sin(deg(\x));
  r2(\x) = 1;
  }
]

% a groupplot is a collection of axes organized in a grid
\begin{groupplot}[
  % set the size of the grid
  group style={group size=2 by 1},
  % default options for both axes:
  % style of axis
  axis lines=center,
  % default domain to plot and number of samples to calculate in that domain
  domain=0:2*pi,
  samples=50,
  % 
  enlargelimits=0.1,
  % set default options for all plots
  every axis plot/.append style={
    very thick,
    no markers
    }
]
\nextgroupplot[
   % define labels for the x- and y-axis
   xlabel=$x$,
   ylabel=$y$,
   % use same unit vectors for x and y, so a circle looks like a circle
   axis equal,
   % define which values to place ticks on the axes, and which labels to use
   ytick=\empty,
   xtick={0.1, 0.5, 1},
   xticklabels={$r_0$, $r_1$, $r_2$},
]

% make parametric plots with x = r * cos(theta) and y = r * sin(theta)
% I used the default plotting variable name x for theta
  \addplot +[arrow on path=0.2] ({r0(x)*cos(deg(x))}, {r0(x)*sin(deg(x))});
  \addplot +[arrow on path] ({r1(x)*cos(deg(x))}, {r1(x)*sin(deg(x))});
  \addplot +[arrow on path] ({r2(x)*cos(deg(x))}, {r2(x)*sin(deg(x))});
  


\nextgroupplot[
  xlabel={$\theta$},
  ylabel={$r$},
  ytick={0.1, 0.5, 1},
  yticklabels={$r_0$, $r_1$, $r_2$},
  xtick={2*pi},
  xticklabels={$2\pi$}
]

% plot the radii as functions of the angle
  \addplot {r0(x)};
  \addplot {r1(x)};
  \addplot {r2(x)};

  \draw [dashed] (2*pi,0) -- (2*pi, 1.1);

\end{groupplot}
\end{tikzpicture}
\end{document}

相关内容