我想制作下图:
我已经的代码是:
\documentclass{standalone}
\usepackage[english, greek]{babel}
\usepackage{ucs}
\usepackage[utf8x]{inputenc}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage{tikz}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{graphicx}
\usepackage{epstopdf}
\usepackage[usenames,dvipsnames]{xcolor}
\begin{document}
\begin{tikzpicture}
\draw[very thick, ->] (0,0)--(0,5) node[left] {Επίπεδο Οικονομικής Δραστηριότητας};
\draw[very thick, ->] (0,0)--(5,0) node[below right] {Χρόνος};
\draw[thick, Blue, -] (.7,.7) node[above left] {$A$}--(4.2,4) node[above right]{$B$};
\end{tikzpicture}
\end{document}
我怎样才能使图形的曲线部分(红色部分)?我怎样才能旋转每个单词?
该图片更像下面的内容:
答案1
您可以将衰减正弦函数叠加在线性增长函数上以获得类似的结果。要放置节点,您可以node [pos=<fraction>, sloped] {<text>}
在命令末尾添加\addplot
:
\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
domain=0:6*pi,
samples=100,
axis lines*=left,
xtick=\empty, ytick=\empty,
width=13cm, height=8cm
]
\addplot [thick, gray] {x};
\addplot [thick, black] {x + 4*sin(deg(x)) * sin(deg(x/6))^0.5}
node [pos=0.1, anchor=south] {Peak}
node [pos=0.3, anchor=south, sloped] {Expansion}
node [pos=0.49, anchor=south, sloped] {Recession}
;
\end{axis}
\end{tikzpicture}
\end{document}
根据 Mico 的建议,以下是该函数的解释。基本上,它只是线性函数和正弦波的总和:
这看起来还不错,但请注意,图的开始和结束处的梯度比线性函数陡峭得多,而 giannis 的第二张图像中的图的梯度等于(或至少相似)线性函数的梯度。
获得类似结果的一种方法是将正弦函数与一个函数相乘,该函数在域的开始和结束附近很小,在域的中心附近接近 1,从而衰减正弦函数。此类函数的一个例子是sin(deg(x/6))^0.5
(通过反复试验找到)。
综合起来:
答案2
以下是元帖子directiontime
它使用在指定方向上行进时查找路径上点的函数,自动找到波浪上标签的正确位置。
请注意,directiontime
通常会找到具有指定方向的路径上的最早点,所以在这里我必须将其放在循环中并沿着路径前进。 directiontime
当找不到方向时返回 -1 ;我用它来结束循环。
我还将标签保存为变量来重新使用它们picture
。
这已被包裹起来,luamplib
因此您需要使用以下命令进行编译lualatex
:
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\mplibtextextlabel{enable}
\usepackage{fontspec}
\setmainfont{Helvetica}
\begin{document}
\begin{mplibcode}
beginfig(1);
% fiddle with the parameters to get a nice rising wave
path wave;
wave = (origin for t=1 step 1 until 3*360 + 24:
-- (2/3t,70 sind(t)) shifted (0,1/3*t)
endfor) scaled 3/4 shifted (21,34);
% draw the straight arrow and the wave on top
drawarrow point 0 of wave -- point 3*360 of wave scaled 1.05
dashed evenly withcolor .5[blue, white];
draw wave withpen pencircle scaled 1 withcolor .67 green;
% label pictures
picture s[];
s1 = thelabel.top("peak", origin);
s2 = thelabel.bot("trough", origin);
s3 = thelabel.top("expansion", origin);
s4 = thelabel.top("recession", origin);
% add the labels in the "right" places
t = 0; n = 0;
forever:
dt := directiontime right of subpath(t,infinity) of wave;
exitif dt < 0;
t := t + dt;
n := n + 1;
if odd(n): draw s1 shifted point t of wave withcolor .67 blue;
if n>1: draw s3 rotated angle direction t-dt/2 of wave
shifted point t-dt/2 of wave ; fi
else: draw s2 shifted point t of wave withcolor .67 red;
draw s4 rotated angle direction t-dt/2 of wave
shifted point t-dt/2 of wave;
fi
endfor
% do the axes and titles
path xx, yy;
xx = origin -- (xpart point infinity of wave, 0);
yy = origin -- (0, ypart point infinity of wave);
drawarrow xx;
drawarrow yy;
label.bot(TEX("Time") scaled 1.2, point 1/2 of xx);
label.lft(TEX("Level of real output") scaled 1.2 rotated 90, point 1/2 of yy);
label.urt(TEX("The business cycle") scaled 1.44, point 0.8 of yy shifted 10 right) withcolor .8 red;
endfig;
\end{mplibcode}
\end{document}
因为我的 Mac 上的 Helvetica 版本包含了全部的希腊字符,并且lualatex
完全支持 Unicode,所以要获得希腊语版本,您只需将七个标签替换为希腊语版本:
s1 = thelabel.top("κρίση", origin);
s2 = thelabel.bot("ύφεση", origin);
s3 = thelabel.top("άνοδος", origin);
s4 = thelabel.top("κἀθοδος", origin);
label.bot(TEX("Χρὀνος") scaled 1.2, point 1/2 of xx);
label.lft(TEX("Επἰπεδο οικονομικἠς δραστηριὀτητας") scaled 1.2 rotated 90, point 1/2 of yy);
label.urt(TEX("Οι φἀσεις του Οικονομικοὐ Κὐκλου") scaled 1.44, point 0.8 of yy shifted 10 right) withcolor .8 red;
如果你把这些版本放在正确的位置并重新编译,你应该得到:
旧的原始版本
最初回答这个问题的时候,我还在使用老式的 Metapost,直接用 编译mpost
。那时的字体管理有点困难。我保留了旧版本以供比较。
编译这个以mpost
获得 PostScript 输出。
prologues := 3;
outputtemplate := "%j%c.eps";
beginfig(1);
string ff; ff = "phvr8r";
% fiddle with the parameters to get a nice rising wave
path wave;
wave = (origin for t=1 step 1 until 3*360 + 24:
-- (2/3t,70 sind(t)) shifted (0,1/3*t)
endfor) scaled 3/4 shifted (21,34);
% draw the straight arrow and the wave on top
drawarrow point 0 of wave -- point 3*360 of wave scaled 1.05
dashed evenly withcolor .5[blue, white];
draw wave withpen pencircle scaled 1 withcolor .67 green;
% labels
picture s[]; % center each label and push it up/down slightly
s1 = "peak" infont ff; s1 := s1 shifted (-1/2 xpart urcorner s1, 6);
s2 = "trough" infont ff; s2 := s2 shifted (-1/2 xpart urcorner s2, -12);
s3 = "expansion" infont ff; s3 := s3 shifted (-1/2 xpart urcorner s3, 6);
s4 = "recession" infont ff; s4 := s4 shifted (-1/2 xpart urcorner s4, 6);
% add the labels in the "right" places
t = 0; n = 0;
forever:
dt := directiontime right of subpath(t,infinity) of wave;
exitif dt < 0;
t := t + dt;
n := n + 1;
if odd(n): draw s1 shifted point t of wave withcolor .67 blue;
if n>1: draw s3 rotated angle direction t-dt/2 of wave
shifted point t-dt/2 of wave ; fi
else: draw s2 shifted point t of wave withcolor .67 red;
draw s4 rotated angle direction t-dt/2 of wave
shifted point t-dt/2 of wave;
fi
endfor
% do the axes and titles
path xx, yy;
xx = origin -- (xpart point infinity of wave, 0);
yy = origin -- (0, ypart point infinity of wave);
drawarrow xx;
drawarrow yy;
label.bot("Time" infont ff scaled 1.2, point 1/2 of xx);
label.lft("Level of real output" infont ff scaled 1.2 rotated 90, point 1/2 of yy);
label.top("The business cycle" infont ff scaled 1.44, point 0.8 of yy shifted 108 right) withcolor .8 red;
% add a little space all round
setbounds currentpicture to bbox currentpicture;
endfig;
end.
要制作希腊语版本(旧方法),您需要将 TeX 处理切换为 LaTeXmpost -tex=latex
并使用该gfsneohellenic
包。
beginfig(2);
verbatimtex
\documentclass{article}
\usepackage[english,greek]{babel}
\usepackage[iso-8859-7]{inputenc}
\usepackage{cmbright}
\usepackage[default]{gfsneohellenic}
\begin{document}
etex
% fiddle with the parameters to get a nice rising wave
path wave;
wave = (origin for t=1 step 1 until 3*360 + 24:
-- (2/3t,70 sind(t)) shifted (0,1/3*t)
endfor) scaled 3/4 shifted (21,34);
% draw the straight arrow and the wave on top
drawarrow point 0 of wave -- point 3*360 of wave scaled 1.05
dashed evenly withcolor .5[blue, white];
draw wave withpen pencircle scaled 1 withcolor .67 green;
% labels
picture s[]; % center each label and push it up/down slightly
s1 = btex \textneohellenic{kr'ish} etex; s1 := s1 shifted (-1/2 xpart urcorner s1, 6);
s2 = btex \textneohellenic{'ufesh} etex; s2 := s2 shifted (-1/2 xpart urcorner s2, -12);
s3 = btex \textneohellenic{'anodoc} etex; s3 := s3 shifted (-1/2 xpart urcorner s3, 6);
s4 = btex \textneohellenic{k'ajodoc} etex; s4 := s4 shifted (-1/2 xpart urcorner s4, 6);
% add the labels in the "right" places
numeric t, n, dt;
t = 0; n = 0;
forever:
dt := directiontime right of subpath(t,infinity) of wave;
exitif dt < 0;
t := t + dt;
n := n + 1;
if odd(n): draw s1 shifted point t of wave withcolor .67 blue;
if n>1: draw s3 rotated angle direction t-dt/2 of wave
shifted point t-dt/2 of wave ; fi
else: draw s2 shifted point t of wave withcolor .67 red;
draw s4 rotated angle direction t-dt/2 of wave
shifted point t-dt/2 of wave;
fi
endfor
% do the axes and titles
path xx, yy;
xx = origin -- (xpart point infinity of wave, 0);
yy = origin -- (0, ypart point infinity of wave);
drawarrow xx;
drawarrow yy;
label.bot(btex \textneohellenic{Qr'onoc} etex scaled 1.2, point 1/2 of xx);
label.lft(btex \textneohellenic{Ep'ipedo oikonomik'hc drasthri'othtac} etex scaled 1.2 rotated 90, point 1/2 of yy);
label.top(btex \textneohellenic{Oi f'aseic tou Oikonomiko'u K'uklou} etex scaled 1.44, point 0.8 of yy shifted 160 right) withcolor .8 red;
% add a little space all round
setbounds currentpicture to bbox currentpicture;
endfig;
答案3
以下是一些可以帮助您入门的内容。您可以调整各个位置的文本或删除不需要的任何节点:
笔记:
- 这并不像我开始时想象的那么灵活,所以也许其他人会想出更聪明的方法来做到这一点。
代码:
\documentclass{article}
\usepackage{xcolor}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\newcommand*{\MyNode}[3][]{%
% #1 = node options
% #2 = x location
% #3 = text
\node [#1] at (axis cs: #2*pi, {sin(deg(#2*pi))}) {#3};
}
\tikzset{My Node Style/.style={font=\tiny, sloped}, above, text=black}
\newcommand*{\RotateAngle}{25}%
\begin{document}
\begin{tikzpicture}[rotate=\RotateAngle, scale=1.0]
\begin{axis}[
axis y line=none,
axis x line=none,
]
\addplot [mark=none, ultra thick, draw=red, samples=200, domain=-0.3*pi:4.2*pi]
{sin(deg(x))};
%% Easier to place the nodes when the domain is a multiple of 2pi, so we
%% redo the plot without actually drawing it.
\addplot [mark=none, ultra thick, draw=none, samples=200, domain=-1*pi:5*pi]
{sin(deg(x))}
node [pos=0.20, My Node Style] {$0.20$}
node [pos=0.30, My Node Style] {$0.30$}
node [pos=0.35, My Node Style] {$0.35$}
node [pos=0.55, My Node Style] {$0.55$}
node [pos=0.65, My Node Style] {$0.65$}
node [pos=0.675, My Node Style] {$0.675$}
node [pos=0.81, My Node Style] {$0.81$}
node [pos=0.86, My Node Style] {$0.86$}
;
%% nodes at the peaks are better placed separately. Am assuming you want
%% these labels horizontal hence have added rotate=-\RotateAngle
\MyNode[My Node Style, rotate=-\RotateAngle, above]{0.5}{$0.5\pi$};
\MyNode[My Node Style, rotate=-\RotateAngle, below]{1.5}{$1.5\pi$};
\MyNode[My Node Style, rotate=-\RotateAngle, above]{2.5}{$2.5\pi$};
\MyNode[My Node Style, rotate=-\RotateAngle, below]{3.5}{$3.5\pi$};
%% Draw the straight line
\addplot [mark=none, ultra thick, blue, domain=-1.5*pi:6*pi] {0}
node [text=black, pos=0, rotate=-\RotateAngle, left] {A}
node [text=black, pos=1, rotate=-\RotateAngle, right] {B}
;
\end{axis}
\draw [rotate=-\RotateAngle, gray, thick, -latex] (-2,0) -- (-2,7)
node [left, align=left, text=black, text width=1.1cm, inner sep=0, outer sep=0]
{$x$-Axis Label};
\draw [rotate=-\RotateAngle, gray, thick, -latex] (-2,0) -- (5,0)
node [below, text=black] {$y$-axis Label};
\end{tikzpicture}
\end{document}
答案4
这是使用“纯”TikZ 方法的另一种选择。曲线是使用控制点绘制的:
代码(控制值以\Angle
获得所需的路径倾角):
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings,backgrounds}
\begin{document}
\begin{tikzpicture}
\def\Angle{25}
\begin{scope}[rotate=\Angle]
\draw[thick,dashed,-latex]
(1cm,0cm) -- (13cm,0cm);
\draw[
thick,
draw=green!80!black,
decoration={
markings,
mark=at position 0.2 with {\node[below,rotate=-60+\Angle] {Recession};},
mark=at position 0.4 with {\node[above,rotate=60+\Angle] {Expansion};},
mark=at position 0.6 with {\node[below,rotate=-60+\Angle] {Recession};},
mark=at position 0.8 with {\node[above,rotate=60+\Angle] {Expansion};}
},
postaction={decorate}
]
(2cm,0cm) .. controls ++(0.75cm,1.5cm) and ++(-0.75cm,1.5cm) ..
node[above=4pt,anchor=east,blue] {Peak}
(4cm,0cm) .. controls ++(0.75cm,-1.5cm) and ++(-0.75cm,-1.5cm) ..
node[below=4pt,anchor=west,red!80!black] {Trough}
(6cm,0cm) .. controls ++(0.75cm,1.5cm) and ++(-0.75cm,1.5cm) ..
node[above=4pt,anchor=east,blue] {Peak}
(8cm,0cm) .. controls ++(0.75cm,-1.5cm) and ++(-0.75cm,-1.5cm) ..
node[below=4pt,anchor=west,red!80!black] {Trough}
(10cm,0cm) .. controls ++(0.75cm,1.5cm) and ++(-0.75cm,1.5cm) ..
node[above=4pt,anchor=east,blue] {Peak}
(12cm,0cm);
\end{scope}
\begin{pgfonlayer}{background}
\filldraw[
shade,
top color=cyan!18,
bottom color=orange!2,
]
([shift={(-1cm,1cm)}]current bounding box.north west)
rectangle
([shift={(1cm,-1cm)}]current bounding box.south east);
\end{pgfonlayer}
\node[below=5pt]
at (current bounding box.south)
{Time};
\node[left=20pt,rotate=90,anchor=north]
at (current bounding box.west)
{Level of real output};
\node[below=7pt,anchor=north,font=\Large,text=red]
at (current bounding box.north)
{The business cycle};
\end{tikzpicture}
\end{document}