从交点到轴绘制垂直线

从交点到轴绘制垂直线

我想从相交点到轴绘制垂直线。

\documentclass{standalone}
\usepackage{pgf, tikz}
\usetikzlibrary{plotmarks,arrows,calc}
\usepackage{pgfplots}

\begin{document}
    \begin{tikzpicture}[font=\sffamily, >=latex]

    % Clip Plot Area
    \clip (-1,-1) rectangle (8,8);

    % Axis
    \draw [->] (-0.5,0) -- coordinate (x axis mid) (8,0);
    \draw [->] (0,-0.5) -- coordinate (y axis mid) (0,8);

    % Ticks
    \foreach \a in {-0.5,0,1,...,8}
        \draw (\a, 2pt) -- (\a, -2pt)  (2pt, \a) -- (-2pt, \a);

    % Axis labels
    \node[below=0.2cm] at (x axis mid) {Quantity of Euro};
    \node[rotate=90, above=0.2cm] at (y axis mid) {Price of Euro};

    % Demand Line
    \draw (0,0) coordinate(d0min) -- (6,6) coordinate(d0max);
    \draw (0,2) coordinate(d1min) -- +($(d0max)-(d0min)-(0.5,0.5)$) coordinate(d1max);

    % Supply Line
    \draw (0,6) coordinate(s0min) -- (6,0) coordinate(s0max);
    \draw ($(s0min)+(1,1)$) coordinate(s1min) -- +($(s0max)-(s0min)$) coordinate(s1max);

    % Intersection Points
    \coordinate (d0s0) at (intersection of d0min--d0max and s0min--s0max);
    \coordinate (d0s1) at (intersection of d0min--d0max and s1min--s1max);
    \coordinate (d1s0) at (intersection of d1min--d1max and s0min--s0max);
    \coordinate (d1s1) at (intersection of d1min--d1max and s1min--s1max);
    % Draw Points
    \draw[fill=black] (d0s0) circle (1pt);
    \draw[fill=black] (d0s1) circle (1pt);
    \draw[fill=black] (d1s0) circle (1pt);
    \draw[fill=black] (d1s1) circle (1pt);

    % Perpendicular lines to axis
    \draw (d0s0) -- (\d0s01,0);
    \end{tikzpicture}
\end{document}

答案1

定义一个坐标(0,0)并使用垂直坐标,如

% Perpendicular lines to axis
\coordinate (o) at (0,0);
\draw[olive] (d0s0|-o) -- (d0s0) -- (d0s0-|o);
\draw[blue,dashed] (d0s1|-o) -- (d0s1) -- (d0s1-|o);
\draw[red,dashed] (d1s0|-o) -- (d1s0) -- (d1s0-|o);
\draw[dashed] (d1s1|-o) -- (d1s1) -- (d1s1-|o);

在此处输入图片描述

(d0s0|-o)表示x坐标与 相同d0s0y坐标与 相同o

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{plotmarks,arrows,calc}

\begin{document}
    \begin{tikzpicture}[font=\sffamily, >=latex]

    % Clip Plot Area
    \clip (-1,-1) rectangle (8,8);

    % Axis
    \draw [->] (-0.5,0) -- coordinate (x axis mid) (8,0);
    \draw [->] (0,-0.5) -- coordinate (y axis mid) (0,8);

    % Ticks
    \foreach \a in {-0.5,0,1,...,8}
        \draw (\a, 2pt) -- (\a, -2pt)  (2pt, \a) -- (-2pt, \a);

    % Axis labels
    \node[below=0.2cm] at (x axis mid) {Quantity of Euro};
    \node[rotate=90, above=0.2cm] at (y axis mid) {Price of Euro};

    % Demand Line
    \draw (0,0) coordinate(d0min) -- (6,6) coordinate(d0max);
    \draw (0,2) coordinate(d1min) -- +($(d0max)-(d0min)-(0.5,0.5)$) coordinate(d1max);

    % Supply Line
    \draw (0,6) coordinate(s0min) -- (6,0) coordinate(s0max);
    \draw ($(s0min)+(1,1)$) coordinate(s1min) -- +($(s0max)-(s0min)$) coordinate(s1max);

    % Intersection Points
    \coordinate (d0s0) at (intersection of d0min--d0max and s0min--s0max);
    \coordinate (d0s1) at (intersection of d0min--d0max and s1min--s1max);
    \coordinate (d1s0) at (intersection of d1min--d1max and s0min--s0max);
    \coordinate (d1s1) at (intersection of d1min--d1max and s1min--s1max);
    % Draw Points
    \draw[fill=black] (d0s0) circle (1pt);
    \draw[fill=black] (d0s1) circle (1pt);
    \draw[fill=black] (d1s0) circle (1pt);
    \draw[fill=black] (d1s1) circle (1pt);

    % Perpendicular lines to axis
    \coordinate (o) at (0,0);
    \draw[olive] (d0s0|-o) -- (d0s0) -- (d0s0-|o);
    \draw[blue,dashed] (d0s1|-o) -- (d0s1) -- (d0s1-|o);
    \draw[red,dashed] (d1s0|-o) -- (d1s0) -- (d1s0-|o);
    \draw[dashed] (d1s1|-o) -- (d1s1) -- (d1s1-|o);
    \end{tikzpicture}
\end{document}

答案2

PSTricks 解决方案:

\documentclass{article}

\usepackage{pst-plot}

\begin{document}

\begin{pspicture}(-1,-1)(8,8)
  \psaxes[labels = none]{->}(0,0)(-1,-1)(8,8)
  \rput(4,-0.7){Quantity of Euro}
  \rput{90}(-0.7,4){Price of Euro}
  \psline(0,0)(6,6)
  \psline(0,2)(5,7)
  \psline(0,6)(6,0)
  \psline(1,7)(7,1)
  \psset{linestyle = dashed, dash = 3pt 3pt} % dash = Xpt Ypt (to get perfectly overlapping dashed with the red and blue lines, we need to have X = Y)
  \psline[linecolor = red](3pt,4)(2,4)(2,0)
  \psline(0,5)(3,5)(3,0)
  \psline[linecolor = blue](0,4)(4,4)(4,0)
  \psline[linecolor = olive](0,3)(3,3)(3,0)
  \psdots(2,4)(3,5)(4,4)(3,3)
\end{pspicture}

\end{document}

输出

相关内容