我真的很喜欢 Ti 生成的“干净”科学轴钾Z'datavisualization
库。但是,由于它提供了相当多的绘图功能,我想尝试pgfplots
一下。我怎样才能在 中模仿datavisualizations
的风格?scientific axes=clean
pgfplots
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{datavisualization.formats.functions}
\usepackage{pgfplots}
\pgfmathsetlengthmacro\axisdefaultwidth{5cm}
\pgfmathsetlengthmacro\axisdefaultheight{\axisdefaultwidth * (sqrt(5) - 1) / 2}
\pgfplotsset{
compat=1.17,
scale only axis,
}
\begin{document}
With Ti\emph kZ:
\vskip 1ex
\begin{tikzpicture}
\datavisualization [
scientific axes=clean,
visualize as line,
]
data [format=function] {
var x : interval [-1.5:1.5] samples 7;
func y = \value x*\value x;
};
\end{tikzpicture}
\vskip 4ex
With \textsc{pgfplots}:
\vskip 1ex
\begin{tikzpicture}
\begin{axis}
\addplot [
domain=-1.5:1.5,
samples=7,
] {x^2};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
这只不过是添加一些键而已。使用
axis lines=left,
axis x line shift=1em,
axis y line shift=1em,
axis line style={-,very thin},
axis background/.style={draw,ultra thin,gray},
tick align=outside,
xtick distance=0.5,
ytick distance=0.5,
在我看来非常接近。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{datavisualization.formats.functions}
\usepackage{pgfplots}
\pgfmathsetlengthmacro\axisdefaultwidth{5cm}
\pgfmathsetlengthmacro\axisdefaultheight{\axisdefaultwidth * (sqrt(5) - 1) / 2}
\pgfplotsset{
compat=1.17,
scale only axis,
}
\begin{document}
With Ti\emph kZ:
\vskip 2ex
\begin{tikzpicture}
\datavisualization [
scientific axes=clean,
visualize as line,
]
data [format=function] {
var x : interval [-1.5:1.5] samples 7;
func y = \value x*\value x;
};
\end{tikzpicture}
\vskip 4ex
With \textsc{pgfplots}:
\vskip 2ex
\begin{tikzpicture}
\begin{axis}[axis lines=left,
axis x line shift=1em,
axis y line shift=1em,
axis line style={-,very thin},
axis background/.style={draw,ultra thin,gray},
tick align=outside,
xtick distance=0.5,
ytick distance=0.5,
]
\addplot [
domain=-1.5:1.5,
samples=7,
] {x^2};
\end{axis}
\end{tikzpicture}
\end{document}
不用说,您可以改变绘图的大小,并将上述键组合成一种样式。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{datavisualization.formats.functions}
\usepackage{pgfplots}
\pgfmathsetlengthmacro\axisdefaultwidth{5cm}
\pgfmathsetlengthmacro\axisdefaultheight{\axisdefaultwidth * (sqrt(5) - 1) / 2}
\pgfplotsset{
compat=1.17,
scale only axis,
}
\begin{document}
With Ti\emph kZ:
\vskip 2ex
\begin{tikzpicture}
\datavisualization [
scientific axes=clean,
visualize as line,
]
data [format=function] {
var x : interval [-1.5:1.5] samples 7;
func y = \value x*\value x;
};
\end{tikzpicture}
\vskip 4ex
With \textsc{pgfplots}:
\pgfplotsset{mimick datavisualization/.style={axis lines=left,
axis x line shift=1em,
axis y line shift=1em,
axis line style={-,very thin},
axis background/.style={draw,ultra thin,gray},
tick align=outside,
xtick distance=0.5,
ytick distance=0.5,
major tick length=2pt}}
\vskip 2ex
\begin{tikzpicture}
\begin{axis}[mimick datavisualization,unit vector ratio=1 1 1,
xmin=-1.5,xmax=1.5,width=5.6cm]
\addplot [semithick,
domain=-1.5:1.5,
samples=7,
] {x^2};
\end{axis}
\end{tikzpicture}
\end{document}