繪製卡諾模型

繪製卡諾模型

我想知道是否有人可以告訴我繪製下圖的最簡單方法。我開始使用 pgfplots 套件中的 axis 環境,正如您從下面的程式碼中看到的那樣,但後來我陷入了困境。

我提前謝謝你!

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}

\begin{axis}[axis lines=middle,axis equal,grid=both]
    \addplot coordinates{(0,0) (5,5) };
\end{axis}

\end{tikzpicture}
\end{document}

卡諾模型

答案1

我認為沒有必要使用pgfplots。我認為您只需使用即可獲得您想要的效果(並且更容易一些)tikz

\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{arrows.meta}
\begin{document}

\begin{tikzpicture}
  \coordinate (Q) at (0,0);

  %% put this first even though you can use opacity. 
  \coordinate (indifferent/nw) at (-0.5in,0.5in);
  \fill[gray,opacity=0.20] (indifferent/nw) rectangle ++ (1in,-1in);
  \path (indifferent/nw) ++ (-0.5cm,0.5cm) node[anchor=south east] (indifferent/label) {indifference};
  \draw (indifferent/nw) -- (indifferent/label.base east);

  \draw[arrows=-Stealth,purple]
       (Q) ++ (-2in,0) node [anchor=east,align=center,text width=0.75in]
                            {Need not~fulfilled}
           -- 
           ++ (4in,0)  node [anchor=west,align=center,text width=0.75in]
                            {Need well~fulfilled};
  \draw[arrows=-Stealth,purple]
       (Q) ++ (0,-2in) node [anchor=north,align=center,text width=0.75in]
                            {dissatisfied}
           -- 
           ++ (0,4in)  node [anchor=south,align=center,text width=0.75in]
                            {satisfied};

  \draw[blue,text=blue] 
              (Q) ++ (-2in,-2in) 
                  -- 
                  ++ (4in,4in) node[pos=0.75,anchor=north west] {Performance};


  \draw[red,text=red] 
             (Q) ++ (-2in,0.25cm) .. controls (-0.5cm,0.25cm) and
                                              ( 0.5cm,1.00cm)
                                  ..            
                    (1.25in,2in)
                    node[pos=0.95,anchor=south east] {Excitement};


 \draw[red,text=red]
            (Q) ++ (-1.25in,-2in) .. controls (-0.5cm,-1.00cm) and
                                              ( 0.5cm,-0.45cm)
                                  ..
                   (2in,-0.5cm)
                   node[pos=0.80,anchor=north west] {Basic};


\end{tikzpicture}

\end{document}

在此輸入影像描述

這裡的基本想法是\draw命令實際上是一種路徑,並且node可以沿著這些路徑定義 s。特別是,我們可以透過使用節點pos=<val>的可選參數來指定節點的位置。錨定有助於將文字放置在我們想要的相對位置。 text width結合使用align有助於使標籤沿x- 軸包裹並居中(我曾經~wellfulfilled粘在一起)。最後,文字的顏色也可以text=<color>在可選參數中指定。最後,我用來.. controls (<coordinate>) and (<coordinate>) ..建構曲線。現在我想到我應該嘗試讓這些變得更漸近表現,但我讓你調整它。

答案2

對於這種半技術草圖,您可能會考慮梅塔普斯特作為替代工具。在這裡,我遵循我的首選順序來保持一切井然有序:定義路徑(盡可能相互相對);畫出它們;然後添加標籤。

在此輸入影像描述

prologues := 3;
outputtemplate := "%j%c.eps";

beginfig(1);
% set a unit scale
u := 1cm;

% define the various paths 
path fulfillment, satisfaction, indifference, performance, excitement, basic;
indifference = unitsquare shifted -(1/2,1/2) scaled 2u;
fulfillment  = (left--right) scaled 3u;
satisfaction = fulfillment rotated 90;
performance  = (xpart point 0 of fulfillment, ypart point 0 of satisfaction) 
            -- (xpart point 1 of fulfillment, ypart point 1 of satisfaction);

excitement = point 0 of fulfillment shifted (0,1/3u) 
             {direction 0 of fulfillment} ..
             {direction 1 of performance}
             point 1 of performance shifted (-1/3u,0);

basic = excitement rotated 180;

% draw the paths
fill      indifference withcolor .9 white;
drawarrow fulfillment  withcolor .5 white;
drawarrow satisfaction withcolor .5 white;
draw      performance  withcolor .67 blue;
draw      excitement   withcolor .67 red;
draw      basic        withcolor .67 green;

% do the labels
verbatimtex
\font\ss=phvr8r\ss
\def\s#1{$\vcenter{\halign{\hfil{##}\hfil\cr#1\crcr}}$}\let\\\cr
etex

label(btex \s{satisfied} etex, point 1 of satisfaction shifted 10 up);
label(btex \s{dissatisfied} etex, point 0 of satisfaction shifted 10 down);

label(btex \s{needs not\\fulfilled}  etex, point 0 of fulfillment shifted 28 left);
label(btex \s{needs well\\fulfilled} etex, point 1 of fulfillment shifted 28 right);

z1 = point 3 of indifference shifted (-u/2,u/2); draw point 3 of indifference -- z1 withcolor .9 white;
label.lft(btex \s{indifference} etex, z1 + 3 up) withcolor .7 white;

label.ulft(btex \s{excitement}  etex, point .9 of excitement)  withcolor .67 red;
label.lrt (btex \s{performance} etex, point .8 of performance) withcolor .67 blue;
label.lrt (btex \s{basic}       etex, point .2 of basic)       withcolor .67 green;

endfig;
end.

筆記

  • 上面的連結向您展示了將 MP 整合到工作流程中的各種方法,並包含指向手冊的連結。

  • 我為所有路徑使用了相當長的名稱,以便您可以更輕鬆地追蹤正在執行的操作

  • u您可以透過調整頂部的值來變更繪圖的比例。

  • 直路只有一段,所以point 0是起點,也是point 1終點。

  • 我將其定義為順時針旋轉 90 度satisfaction的副本,以及旋轉 180 度的副本。fulfillmentbasicexcitement

  • 我定義了一些非常簡單的純 TeX 指令,讓我可以整齊地設定標籤。您也可以使用 LaTeX,如手冊中所述。事實上,透過gmp包,或透過luatexcontext你可以將 MP 程式碼作為 LaTeX 原始檔的一部分包含進來,例如 TikZ。

相關內容