我是 Latex 新手,想绘制一个 x 轴有间隔的图形。我有这个非间隔的示例代码:
\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}
\usepackage{pgfplots}
\pgfplotsset{width=10cm,compat=1.9} %Changed 1cm to 10cm so plot is visible RMS
%\usepgfplotslibrary{external}
%\tikzexternalize
\begin{document}
Plotting from data:
\begin{tikzpicture}
\begin{axis}[
title={Temperature dependence of CuSO$_4\cdot$5H$_2$O solubility},
xlabel={Temperature [\textcelsius]},
ylabel={Solubility [g per 100 g water]},
xmin=0, xmax=100,
ymin=0, ymax=120,
xtick={0,20,40,60,80,100},
ytick={0,20,40,60,80,100,120},
legend pos=north west,
ymajorgrids=true,
grid style=dashed,
]
\addplot[
color=blue,
mark=square,
]
coordinates {
(0,23.1)(10,27.5)(20,32)(30,37.8)(40,44.6)(60,61.8)(80,83.8)(100,114)
};
\addplot[
color=red,
mark=square,
]
coordinates{
(0,40)(20,60)
};
\legend{CuSO$_4\cdot$5H$_2$O, random, yo}
\end{axis}
\end{tikzpicture}
\end{document}
此外,假设我有两个相似的图形,并且想将它们水平组合在一起,我该怎么做并在其下方添加一个文本框?
谢谢你!
答案1
间隔
我无法在评论中发布图片,因此我使用答案功能。你的意思是这样的吗(你必须仔细观察才能看到细小的刻度线):
在当前pgfplots 文档(修订版 1.12)第 286 页(第 4.15 章)有以下示例(参见哈里什·库马尔):
\begin{tikzpicture}
\begin{axis}[
ybar interval=0.9,
x tick label as interval,
xmin=2003,xmax=2030,
ymin=0,ymax=140,
xticklabel={
$\pgfmathprintnumber{\tick}$
-- $\pgfmathprintnumber{\nexttick}$},
xtick=data,
x tick label style={
rotate=90,anchor=east,
/pgf/number format/1000 sep=}
]
\addplot[draw=blue,fill=blue!40!white]
coordinates
{(2003,40) (2005,100) (2006,15)
(2010,90) (2020,120) (2030,3)};
\end{axis}
\end{tikzpicture}
导致
描述
x tick label as interval
:允许将刻度标签视为间隔;这意味着刻度位置表示间隔边界。如果有 n 个位置,(n