Tikzpicture 的比例

Tikzpicture 的比例

我对以下代码有疑问:

\begin{tikzpicture}[scale=0.6, >=latex,y=7cm,x=1.8cm]
\draw[-angle 45,line width = 0.8pt] (-5,0) -- (5,0) node[right] {\scriptsize $x$};
\draw[-angle 45,line width = 0.8pt] (0,-0.15) -- (0,1.2) node[above] {\scriptsize $y$};
\foreach \x in {-4,-3,-2,-1,1,2,3,4} \draw (\x, 3pt) -- (\x,-3pt) node[anchor=north] {\tiny \x};
\foreach \y in {0.2,0.4,0.6,0.8,1.0} \draw (3pt,\y) -- (-3pt,\y) node[anchor=east] {\tiny \y};
\draw[color=red, line width = 1pt, domain=0:4, samples=100]     plot (\x,{3/32*(2*(\x)^2-(1/3)*(\x)^3)});
\draw[color=red, line width = 1pt, domain=-5:0, samples=100]     plot (\x,{0});
\draw[color=red, line width = 1pt, domain=4:5, samples=100]     plot (\x,{1});
\end{tikzpicture}

如何计算两个轴的绝对尺寸。例如“y=7cm”是什么意思?

答案1

xy选项中的和tikzpicture可用于固定xy单位尺寸,默认情况下为1 cm。在您的代码中,每个垂直单位长 7 厘米,每个 x 单位长 1.8 厘米。但如果您使用值+单位格式,它代表实际尺寸。

\documentclass[tikz,border=2mm]{standalone}
\usepackage{siunitx}

\begin{document}
\begin{tikzpicture}[x=1.8cm, y=7cm]

\draw[help lines] (0,0) grid[xstep=1cm,ystep=1cm] (3cm,8cm);

\draw (0,0) -- (1,1) node[above] {(1,1)};
\draw (0,0)-- (2cm,1cm)  node[above] {(\SI{2}{\centi\meter},\SI{1}{\centi\meter})};;
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容