tikz:縮放 y 軸

tikz:縮放 y 軸

我想縮放 y 軸,以便我的圖在 y 軸上不那麼微觀。但是,當我使用yscale = xx 是某個數字時,圖像和圓圈會變形。我想拉長 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}

相關內容