我正在尝试将 pgfplot 放在预先存在的 tikz 图片中。但不知何故,我用 pfgplot 创建的轴有不同的单位,我不确定如何使这两个东西适合。
代码如下:
\documentclass[11pt]{amsart}
\usepackage{geometry} % See geometry.pdf to learn the layout options. There are lots.
\geometry{letterpaper} % ... or a4paper or a5paper or ...
%\geometry{landscape} % Activate for for rotated page geometry
%\usepackage[parfill]{parskip} % Activate to begin paragraphs with an empty line rather than an indent
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{epstopdf}
\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}
\title{Brief Article}
\author{The Author}
%\date{} % Activate to display a given date or no date
\begin{document}
\maketitle
\begin{tikzpicture}[scale=1]
\draw [line width=0.05cm] (0,1) to [out=80,in=180] (1,1) to [out=0,in=180] (2.5,1.5) to [out=0,in=-100] (4,1);
\draw [line width=0.05cm] (0,3) to [out=25,in=150] (1.5,3.5) to [out=-30,in=120] (3,3) to [out=-50,in=-155] (4,3);
\draw [thin, ->] (-0.1,0) -- (4.5,0);
\draw [thin, ->] (0, -0.1) -- (0, 4.5);
\draw [thin] (4, -0.1) -- (4, 0.1);
\draw [line width=0.05cm, red] (1, 1) to [out=0, in=180] (1.5, 1.5);
\draw [line width=0.05cm, red] (2.5, 2.5) to [out=0, in=180] (3, 3);
\begin{axis}[samples=3000]
\addplot[very thick,red ]plot (\x, {\x*sin(1/abs(\x))});
\end{axis}
\end{tikzpicture}
\end{document}
我希望函数 x sin(1/|x|) 的图形(经过适当缩放和平移)能够以某种方式平滑地连接两条预先存在的红线。
任何帮助将不胜感激。
** 编辑 **
以下是一些改进的代码:
\begin{tikzpicture}
\path [fill=lightgray] (0,1) to [out=80,in=180] (1,1) to [out=0,in=180] (2.5,1.5) to [out=0,in=-100] (4,1) to (4,0) to (0,0);
\draw [line width=0.05cm] (0,1) to [out=80,in=180] (1,1) to [out=0,in=180] (2.5,1.5) to [out=0,in=-100] (4,1);
\path [fill=lightgray] (0,3) to [out=25,in=150] (1.5,3.5) to [out=-30,in=120] (3,3) to [out=-50,in=-155] (4,3) to (4,4.3) to (0,4.3); \draw [line width=0.05cm] (0,3) to [out=25,in=150] (1.5,3.5) to [out=-30,in=120] (3,3) to [out=-50,in=-155] (4,3); \draw [thin, ->] (-0.1,0) -- (4.5,0);
\draw [thin, ->] (0, -0.1) -- (0, 4.5);
\draw [thin] (4, -0.1) -- (4, 0.1);
\node [below] at (4, -0.1) {$2\pi$};
\node [below] at (0, -0.1) {$0$};
\draw [dashed] (-0.1, 2) -- (4,2);
\draw [line width=0.05cm, red] (1, 1) to [out=0, in=180] (1.5,1.5);
\draw [line width=0.05cm, red] (2.5,2.5) to [out=0, in=180] (3, 3);
\begin{axis}[samples=9000,scale only axis,axis lines=none]
\addplot[very thick,red ]plot (\x, {0.1*(\x + 3)*sin((1/abs((\x + 3)))r)});
\end{axis}
结果:
答案1
如果我正确理解了你的问题,以下内容应该会产生你想要的曲线,但并没有解决标题中关于放置pgfplots axes
在 内的问题tikzpicture
。
\documentclass[11pt]{amsart}
\usepackage{tikz}
\usepackage{pgfplots}
\title{Brief Article}
\author{The Author}
\begin{document}
\maketitle
\begin{tikzpicture}[scale=1]
\draw [line width=0.05cm] (0,1) to [out=80,in=180] (1,1) to [out=0,in=180] (2.5,1.5) to [out=0,in=-100] (4,1);
\draw [line width=0.05cm] (0,3) to [out=25,in=150] (1.5,3.5) to [out=-30,in=120] (3,3) to [out=-50,in=-155] (4,3);
\draw [thin, ->] (-0.1,0) -- (4.5,0);
\draw [thin, ->] (0, -0.1) -- (0, 4.5);
\draw [thin] (4, -0.1) -- (4, 0.1);
\draw [line width=0.05cm, red] (1, 1) to [out=0, in=180] (1.5,1.5);
\draw[line width=0.05cm, red,rounded corners=2pt] (1.5,1.5) -| (2,2) |- (2.5,2.5);
\draw [line width=0.05cm, red] (2.5,2.5) to [out=0, in=180] (3, 3);
\end{tikzpicture}
\end{document}
编辑:
TikZ\draw
命令可以在axis
环境中运行,坐标(x,y)
将与当前坐标系相对应。考虑到这一点,一种方法是基本上绘制一个具有两个坐标的图,然后在一个轴上绘制阴影区域,在另一个轴上绘制函数。理想情况下,x 轴应该相同,y 轴可以有不同的比例,但在下面的代码中,我只是手动排列它们,而不是更改阴影区域的所有坐标。
\documentclass[11pt]{amsart}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\title{Brief Article}
\author{The Author}
\begin{document}
\maketitle
\begin{tikzpicture}
\begin{axis}[axis lines=none,
xmin=-1,
xmax=5,
ymin=-1,
ymax=5]
\draw [fill=lightgray] (0,1) to [out=80,in=180] (1,1) to [out=0,in=180] (2.5,1.5) to [out=0,in=-100] (4,1) to (4,0) to (0,0);
\draw [line width=0.05cm] (0,1) to [out=80,in=180] (1,1) to [out=0,in=180] (2.5,1.5) to [out=0,in=-100] (4,1);
\path [fill=lightgray] (0,3) to [out=25,in=150] (1.5,3.5) to [out=-30,in=120] (3,3) to [out=-50,in=-155] (4,3) to (4,4.3) to (0,4.3); \draw [line width=0.05cm] (0,3) to [out=25,in=150] (1.5,3.5) to [out=-30,in=120] (3,3) to [out=-50,in=-155] (4,3); \draw [thin, ->] (-0.1,0) -- (4.5,0);
\draw [thin, ->] (0, -0.1) -- (0, 4.5);
\draw [thin] (4, -0.1) -- (4, 0.1);
\node [below] at (4, -0.1) {$2\pi$};
\node [below] at (0, -0.1) {$0$};
\draw [dashed] (-0.1, 2) -- (4,2);
\draw [line width=0.05cm, red] (1, 1) to [out=0, in=180] (1.5,1.5);
\draw [line width=0.05cm, red] (2.5,2.5) to [out=0, in=180] (3, 3);
\end{axis}
\begin{axis}[axis lines=none,
xmin=-6,
xmax=6,
ymin=-5.1,
ymax=5.1
]
\addplot[very thick,red,samples=1000,restrict x to domain=-1.1:1.1]
plot (\x, {(\x)*sin((1/abs((\x)))r)});
\end{axis}
\end{tikzpicture}
\end{document}
我承认,这并不优雅,但希望这种方法能够有所帮助。