我想使用 LaTeX 复制如下图所示的图表。
我已经发现本教程并以此作为创建图表的基础。
但是,我很难将 Y 轴移动到原点,如下图所示。我怎样才能将 Y 轴移动到原点?
这是我的代码
\documentclass{standalone}
% Required package
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat = newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin = -300, xmax = 100,
ymin = 0, ymax = 7,
width = \textwidth,
height = 0.75\textwidth,
xtick distance = 50,
ytick distance = 1,
grid = both,
minor tick num = 1,
major grid style = {lightgray},
minor grid style = {lightgray!25},
]
% plot data line code
\addplot[teal, only marks] table[x = t, y = x] {result.dat};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
由于您没有提供表格,因此我们很难帮助您,result.dat
因此我们不知道您的标记的坐标在哪里。如果我用坐标(-273,-273)
和 (100,7) 之间的虚拟线替换它,我会得到以下图表(基于您的代码片段):
这是你要找的吗?上图的 MWE(最小工作示例)是:
\documentclass{standalone}
% Required package
\usepackage{pgfplots}
%\usepackage{pgfplotstable}
\pgfplotsset{compat = 1.18}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
grid = both,
minor tick num = 4,
xmin = -300, xmax = 100, xlabel={T (\si{\celsius})},
ymin = -300, ymax = 10, ylabel={V},
major grid style = {lightgray},
minor grid style = {lightgray!25},
]
% plot data line code
\addplot coordinates {(-273,-273) (90,7)};
\end{axis}
\end{tikzpicture}
\end{document}
当您提供缺失的数据时,我可以相应地更正图表。
编辑: 然而,你似乎想要的是以下结果:
\documentclass{standalone}
% Required package
\usepackage{pgfplots}
%\usepackage{pgfplotstable}
\pgfplotsset{compat = 1.18}
\usepackage{siunitx}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
grid=both,
minor tick num = 4,
minor grid style = {lightgray!25},
xmin = -300, xmax = 100, xlabel={T (\si{\celsius})},
ymin = -300, ymax = 50, ylabel={V},
major grid style = {lightgray},
minor grid style = {lightgray!25},
]
% plot data line code
\addplot coordinates {(-273,-273) (90,7)};
\end{axis}
\end{tikzpicture}
\end{document}