刪除 pgfplots 線圖中兩個座標之間的線

刪除 pgfplots 線圖中兩個座標之間的線

儘管我相信我的問題並不是唯一的,但我找不到有關此特定主題的帖子。如果我還沒有找到關於此的線程,請告訴我。

因此,我正在嘗試使用 繪製貨幣價值圖pgfplots。但是,由於貨幣在時間序列的中間發生了變化,因此我想在線條中進行中斷,以便不繪製 1990 年和 2000 年之間的線條。如何刪除這些單行?

我的例子是:

\begin{figure}
\centering
\begin{tikzpicture}
  \begin{axis}[width=\textwidth, xlabel = year,%\,/\,Tsd. Tonnen,
      xmin = 1965, xmax = 2015,
      xtick={1960, 1970, 1980, 1990, 2000, 2010},
      x tick label style={/pgf/number format/1000 sep=},
      ylabel = example,
      ymin = 1000, ymax = 5000,
      y tick label style={/pgf/number format/1000 sep=},]
      \addplot 
      coordinates {
(1960,  1650)
(1970,  2550)
(1980,  4050)
(1990,  4550)
(2000,  3550)
(2010,  3750)
         };
       \addplot 
      coordinates {
(1960,  1600)
(1970,  2500)
(1980,  4000)
(1990,  4500)
(2000,  3500)
(2010,  3700)
         };
\legend{a, b}
   \end{axis}
\end{tikzpicture}
\vspace*{0.4cm} 
\caption[Example.]{Example.}
\end{figure}

圖片看起來像這樣:

在此輸入影像描述

預先感謝您的任何幫助! :)

答案1

一種方法是添加unbounded coords=jumpaxis選項中,並添加1990nan到 2000 之間的座標。(1995, nan)

或者,您可以將時間序列拆分為兩個\addplot,但這會增加更多工作以確保繪圖樣式相同。

在此輸入影像描述

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
  \begin{axis}[width=\textwidth, xlabel = year,%\,/\,Tsd. Tonnen,
      xmin = 1965, xmax = 2015,
      xtick={1960, 1970, 1980, 1990, 2000, 2010},
      x tick label style={/pgf/number format/1000 sep=},
      ylabel = example,
      ymin = 1000, ymax = 5000,
      y tick label style={/pgf/number format/1000 sep=},
      unbounded coords=jump  %%%% added
      ]
      \addplot 
      coordinates {
(1960,  1650)
(1970,  2550)
(1980,  4050)
(1990,  4550)
(1995, nan)
(2000,  3550)
(2010,  3750)
         };
       \addplot 
      coordinates {
(1960,  1600)
(1970,  2500)
(1980,  4000)
(1990,  4500)
(1995, nan)
(2000,  3500)
(2010,  3700)
         };
\legend{a, b}
   \end{axis}
\end{tikzpicture}

\end{document}

相關內容