我正在构建热力学图。基本结构是 ax 轴,以摄氏度为单位表示温度,y 轴,以百帕为单位表示压力,采用对数刻度。然后我需要添加几行,给出以下公式::
这Φ
是下一个预期温度(x 轴),T
是 x 轴上每条线的起始温度,p0
是基本压力,通常为常数 1000。p
是下一个压力(y 轴),k
是一个常数,0.286
。因此,对于 10°,公式将类似于 x = 10(1000/y)^0.286。
我对此图的解释是这样的:
\documentclass[titlepage]{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymode=log,
ymin=95,
ymax=1100,
y dir=reverse,
xmin=-95,
xmax=45,
ylabel=p (hPa),
xlabel=T,
grid=both,
ytick={100,200,300,400,500,600,700,800,900,1000},
width=15cm,
height=15cm,
decoration={name=none},
log ticks with fixed point,
]
\foreach \T in {-90,-80,-70,-60,-50,-40,-30,-20,-10,0,10,20,30,40} {
\addplot [blue, domain=-90:40] {\T * (1000/y)^0.286};
};
\end{axis}
\end{tikzpicture}
\end{document}
返回此错误:
! Package pgfplots Error: Sorry, you can't use 'y' in this context. PGFPlots ex
pected to sample a line, not a mesh. Please use the [mesh] option combined with
[samples y>0] and [domain y!=0:0] to indicate a twodimensional input domain.
如果我遵循以下建议:
\documentclass[titlepage]{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymode=log,
ymin=95,
ymax=1100,
y dir=reverse,
xmin=-95,
xmax=45,
ylabel=p (hPa),
xlabel=T,
grid=both,
ytick={100,200,300,400,500,600,700,800,900,1000},
width=15cm,
height=15cm,
decoration={name=none},
log ticks with fixed point,
]
\foreach \T in {-90,-80,-70,-60,-50,-40,-30,-20,-10,0,10,20,30,40} {
\addplot [blue, mesh, samples y > 0, domain y!=0:0] {\T * (1000/y)^0.286};
};
\end{axis}
\end{tikzpicture}
\end{document}
我收到以下错误:
! Package pgfkeys Error: I do not know the key '/tikz/samples y > 0' and I am g
oing to ignore it. Perhaps you misspelled it.
我被困住了。任何帮助我都会很感激。
编辑:
@AndreyL 建议重新排列公式,用 来表达。p
这样做的问题是,这会呈现完全不同的图表,请参见下图。theta
\addplot [blue, domain=-90:40] {1000*(\T/x)^(1/0.286)};
答案1
嗯,这更多的是物理问题而不是 LaTeX 问题......
从摄氏度转换为开尔文后,我得到了类似的图。我希望现在它看起来是正确的。
\documentclass[border=10]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ymode=log,
ymin=95,
ymax=1100,
y dir=reverse,
xmin=-95,
xmax=45,
ylabel=p (hPa),
xlabel=T,
grid=both,
ytick={100,200,...,1000},
width=15cm,
height=15cm,
decoration={name=none},
log ticks with fixed point,
]
\foreach \T in {-90,-80,...,150} {
\addplot [blue, domain=-90:40] {1000*((273+x)/(273+\T))^(1/0.286)};
};
\end{axis}
\end{tikzpicture}
\end{document}