我想缩放 y 轴,这样我的绘图在 y 轴上就不会显得太过微小。但是,当我使用yscale = x
x 为某个数字时,图像和圆圈会扭曲。我想在不扭曲任何东西的情况下拉长 y 轴。
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[yscale = 2]
% x and y axis
\draw (-0.5cm, 0) -- (9.5cm, 0) node[font = \small, right] {$k$};
\draw (-0.5cm, 0) -- (-0.5cm, 0.1cm) node[font = \small, above] {$p_X$};
% x and y tick marks and probabilities
\foreach \x in {0, 1, ..., 9}{
\draw (\x cm, 0) -- (\x cm, -0.1cm) node[below, font = \small] {$\x$};
\draw[fill = black] (\x cm, 0) -- (\x cm, 0.1cm) circle[radius = 0.025cm];
}
\foreach \y in {0.01, ..., 0.1}{
\draw (-0.5cm, \y cm) -- (-0.6cm, \y cm) node[left, font = \small] {$\y$};
}
\end{tikzpicture}
\end{document}
答案1
问题在于垂直线和圆是同时绘制的。因此不存在只影响垂直线的 y 缩放。使用节点可以解决这个问题。
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw(-0.5,0)--(9.5,0)node[font=\small,right]{$k$};
\draw[yscale=30](-0.5,0)--(-0.5,0.1)node[font=\small,above]{$p_X$};
\foreach\x in{0,...,9}{
\draw(\x,0)--(\x,-0.1)node[below,font=\small]{$\x$};
\draw[yscale=30](\x,0)--(\x,0.1)node[circle,fill,draw,scale=.3]{};}
\foreach\y in{1,...,10}{
\draw[yscale=30](-0.5,\y/100)--(-0.6,\y/100)node[left,font=\small]{$\y$};
}
\end{tikzpicture}
\end{document}