我在 Excel 中有以下图表,我想在 Latex 上尽可能地重现它。
但是,到目前为止我有这个:
除了标签之外,轴刻度和图表本身都是错误的。有人能帮我吗?
我的 MWE 是
\documentclass[a4paper,11pt,oneside]{book}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{siunitx}
\usepackage{pgfplots}
\usetikzlibrary{intersections, calc}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{figure}[h!]
\begin{center}
\begin{tikzpicture}[scale=0.8]
\centering
\begin{axis}[
width= \linewidth,
height = 9cm,
%grid = major,
axis x line = center,
axis y line = center,
xticklabels = {Oct 13, Nov 13, Dec 13, Jan 2014, Feb 14, Mar 14, Apr 14, May 14, Jun 14, Jul 14, Aug 14},
yticklabels = {54,56,58,60,62,64,66},
x tick label style = {rotate=75, anchor=east},
ylabel = Temperature rise on the boiler,
xlabel = time
]
\addplot [mark=x] coordinates {
(1,56)
(2,57)
(3,57)
(4,61)
(5,62)
(6,62)
(7,63)
(8,64)
(9,64)
(10,65)
};
\end{axis}
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}
答案1
如果你不手动用 覆盖 y 轴标签
yticklabels = {...}
,你将获得与你的数据相匹配的标签要显示网格,你只需取消注释
grid = major
如果轴名称应该位于中心,则删除
axis x line = center
并axis y line = center,
center
在图中使用环境将导致额外的垂直间距,请改用\centering
。如果所有数据点在 x 轴上都应该有相应的 x 标签,则从 0 开始计数
\documentclass[a4paper,11pt,oneside]{book}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{siunitx}
\usepackage{pgfplots}
\usetikzlibrary{intersections, calc}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{figure}[h!]
%\begin{center}
\centering
\begin{tikzpicture}[scale=0.8]
\centering
\begin{axis}[
width= \linewidth,
height = 9cm,
grid = major,
%axis x line = center,
%axis y line = center,
xticklabels = {Oct 13, Nov 13, Dec 13, Jan 2014, Feb 14, Mar 14, Apr 14, May 14, Jun 14, Jul 14, Aug 14},
%yticklabels = {54,56,58,60,62,64,66},
x tick label style = {rotate=75, anchor=east},
ylabel = Temperature rise on the boiler,
xlabel = time
]
\addplot [mark=x] coordinates {
(0,56)
(1,57)
(2,57)
(3,61)
(4,62)
(5,62)
(6,63)
(7,64)
(8,64)
(9,65)
};
\end{axis}
\end{tikzpicture}
%\end{center}
\end{figure}
\end{document}
答案2
与@samcarters 一样,答案很好,但还带有网格、项目符号、扩展轴和颜色。
\documentclass[a4paper,11pt,oneside]{book}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{siunitx}
\usepackage{pgfplots}
\usetikzlibrary{intersections, calc}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{figure}[h!]
\begin{center}
\begin{tikzpicture}[scale=0.8]
\centering
\begin{axis}[
width= \linewidth,
height = 9cm,
%grid = major,
axis x line = center,
axis y line = center,
xticklabels = {Oct 13, Nov 13, Dec 13, Jan 2014, Feb 14, Mar 14, Apr 14, May 14, Jun 14, Jul 14, Aug 14},
%yticklabels = {54,56,58,60,62,64,66,68},
x tick label style = {rotate=75, anchor=east},
y tick label style = {fill=white},
ylabel = Temperature rise on the boiler,
ylabel style={rotate=90,anchor=south east,yshift=8mm},
xlabel = time,enlargelimits=0.2,grid=major
]
\addplot [mark=*,blue!40] coordinates {
(1,56)
(2,57)
(3,57)
(4,61)
(5,62)
(6,62)
(7,63)
(8,64)
(9,64)
(10,65)
};
\end{axis}
\end{tikzpicture}
\end{center}
\end{figure}
\end{document}