為什麼 tikz 要報告我的尺寸太大?

為什麼 tikz 要報告我的尺寸太大?

我正在嘗試使用 Tikz 創建一個圖形,但它給了我“尺寸太大錯誤”。我懷疑這是因為我試圖繪製在極限範圍內接近 0 和 1 的函數圖表,而 Tikz 無法完全處理這個問題。關於如何讓 Tikz 工作有什麼建議嗎?

\documentclass{article}
\begin{document}
\begin{tikzpicture}
    \begin{groupplot}[group style={group size= 2 by 1},height=6cm,width=6cm,xmin=0.5,ymin=0.5,ymax=1,xmax=1,samples=500,ytick={0.5,1},xtick={0.5,1}, xlabel={$v_1$},
    axis lines=left]
        \nextgroupplot[title={}, ylabel={$x_1$}]
              \addplot[blue,]{min(1,(\x/(2*(1-min(1,\x)))))};\label{plots:plot1};   

              \addplot[black] {((3*\x-1)/(2*\x))};\label{plots:plot2};
                \addplot[black, dashed] {(\x)};\label{plots:plot3};
         \nextgroupplot[title={}, ylabel={$x_2$}]
              \addplot[blue]{(max((2-3*\x)/(2-2*\x),0))};\label{plots:plot1};        \addplot[black] {(1-\x)/(2*\x)};\label{plots:plot2};
                \addplot[black, dashed] {(1-\x)};\label{plots:plot3};
                \coordinate (top) at (rel axis cs:0,1);% coordinate at top of the first plot
                \coordinate (bot) at (rel axis cs:1,0);% coordinate at bottom of the last plot
    \end{groupplot}
    \path (top-|current bounding box.west)-- 
          node[anchor=south,rotate=90] { } 
          (bot-|current bounding box.west);
% legend
\path (top|-current bounding box.south)--
      coordinate(legendpos) 
      (bot|-current bounding box.south);
\matrix[
    matrix of nodes,
    anchor=north,
    draw,
    inner sep=0.2em,
    draw
  ]at([yshift=-1ex, xshift=-17ex]legendpos)
  {
    \ref{plots:plot1}& F(x)&[5pt]
    \ref{plots:plot2}& G(x)&[5pt]
    \ref{plots:plot3}& H(x)& \\};
\end{tikzpicture} 
\end{document}

答案1

請嘗試使用以下程式碼,並且必須運行LuaLaTeX才能獲得輸出:

\documentclass{article}
\usepackage{pgfplots,tikz}
\usetikzlibrary{matrix,calc,arrows,shapes,positioning}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
    \begin{groupplot}[group style={group size= 2 by 1},height=6cm,width=6cm,xmin=0.5,ymin=0.5,ymax=1,xmax=1,samples=500,ytick={0.5,1},xtick={0.5,1}, xlabel={$v_1$},
    axis lines=left]
        \nextgroupplot[title={}, ylabel={$x_1$}]
              \addplot[blue,]{min(1,(\x/(2*(1-min(1,\x)))))};\label{plots:plot1};   

              \addplot[black] {((3*\x-1)/(2*\x))};\label{plots:plot2};
                \addplot[black, dashed] {(\x)};\label{plots:plot3};
         \nextgroupplot[title={}, ylabel={$x_2$}]
              \addplot[blue]{(max((2-3*\x)/(2-2*\x),0))};\label{plots:plot1};        \addplot[black] {(1-\x)/(2*\x)};\label{plots:plot2};
                \addplot[black, dashed] {(1-\x)};\label{plots:plot3};
                \coordinate (top) at (rel axis cs:0,1);% coordinate at top of the first plot
                \coordinate (bot) at (rel axis cs:1,0);% coordinate at bottom of the last plot
    \end{groupplot}
    \path (top-|current bounding box.west)-- 
          node[anchor=south,rotate=90] { } 
          (bot-|current bounding box.west);
% legend
\path (top|-current bounding box.south)--
      coordinate(legendpos) 
      (bot|-current bounding box.south);
\matrix[
    matrix of nodes,
    anchor=north,
    draw,
    inner sep=0.2em,
    draw
  ]at([yshift=-1ex, xshift=-17ex]legendpos)
  {
    \ref{plots:plot1}& F(x)&[5pt]
    \ref{plots:plot2}& G(x)&[5pt]
    \ref{plots:plot3}& H(x)& \\};
\end{tikzpicture} 
\end{document}

相關內容