
我想寫\gamma
在我的傳奇之上在使用下面所示的程式碼產生的繪圖(如圖所示)中。我通常使用\node at (axis cs: co-ordinate x,co-ordinate y) {text}
情節。由於圖例位於圖之外,我不確定如何使用 存取圖例上方的點\node
。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\begin{document}
\begin{tikzpicture}
\begin{loglogaxis}[
% scale=0.8,
% width=\columnwidth,
% baseline,
ylabel={$G(\gamma,t) \:\: \mathrm{(Pa)}$},
xlabel= t (s),
legend entries ={0.1,0.2,0.4,0.8},
legend style={at={(1.3,0.5)},anchor=east,font=\small},
]
\addplot [color=red,line width=1.5pt] table [x=time,y=m01,row sep=newline] {relaxationExpDatafor65v.dat};
\addplot [color=green,line width=1.5pt] table [x=time,y=m02,row sep=newline] {relaxationExpDatafor65v.dat};
\addplot [color=blue,line width=1.5pt] table [x=time,y=m04,row sep=newline] {relaxationExpDatafor65v.dat};
\addplot [color=cyan,line width=1.5pt] table [x=time,y=m08,row sep=newline] {relaxationExpDatafor65v.dat};
%%fits
\addplot [color=black,line width=1pt,densely dashed] table [x=time,y=m01,row sep=newline] {relaxationExpDataPredfor65v.dat};
\addplot [color=black,line width=1pt,densely dashed] table [x=time,y=m02,row sep=newline] {relaxationExpDataPredfor65v.dat};
\addplot [color=black,line width=1pt,densely dashed] table [x=time,y=m04,row sep=newline] {relaxationExpDataPredfor65v.dat};
\addplot [color=black,line width=1pt,densely dashed] table [x=time,y=m08,row sep=newline] {relaxationExpDataPredfor65v.dat};
\end{loglogaxis}
\end{tikzpicture}
\end{document}
我希望您不需要程式碼中調用的 .dat 檔案(坦白說,我不知道如何上傳它們,因為這是我在這個社區中的第一個問題)。預先感謝您的寶貴時間!
答案1
只需添加label=above:$\gamma$
定義即可legend style
。
作為一個例子,我使用了史蒂文提供的代碼:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width = 1*\textwidth,
height = 4.5cm,
major x tick style = transparent,
ybar=1*\pgflinewidth,
bar width=13pt,
symbolic x coords={A,B,C,D},
xtick = data,
enlarge x limits=0.25,
ymax=15,
ymin=0,
legend cell align=left,
legend style={
at={(1,1.05)},
anchor=south east,
column sep=1ex,
label=above:$\gamma$ %<--------------------
}
]
\addplot[style={fill=red,mark=none}]
coordinates {(A, 4.44) (B,0.1) (C,4.37) (D,4.07)};
\addplot[style={fill=green,mark=none}]
coordinates {(A, 0.4) (B,0.8) (C,0.3) (D,0.5)};
\addplot[style={fill=blue,mark=none}]
coordinates {(A, 0.2) (B,0) (C,0.9) (D,0.8)};
\addplot[style={fill=yellow,mark=none}]
coordinates {(A, 9.59) (B,0.2) (C,8.86) (D,8.62)};
\legend{C1,C2,C3,C4}
\end{axis}
\end{tikzpicture}%
\end{document}
答案2
如果 內部沒有出現答案tikz
,這裡有一種將程式碼包裝在環境外部的方法tikzpicture
。由於我沒有足夠的資源來編譯您的範例,因此我只是從另一個問題中獲取了類似的範例。
完全基於答案註釋分組長條圖,只需改變註釋的位置和註釋的文字,就可以添加註釋。在此 MWE 中,我顯示了兩個嵌套註釋:圖中紅條上方的項目符號;和圖例上的伽瑪。
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{stackengine}[2013-09-11]
\begin{document}
\begin{figure}[]
\stackinset{c}{-3.92cm}{b}{1.52cm}{$\bullet$}{%
\stackinset{r}{.6cm}{t}{-.3cm}{$\gamma$}{%
\begin{tikzpicture}
\begin{axis}[
width = 1*\textwidth,
height = 4.5cm,
major x tick style = transparent,
ybar=1*\pgflinewidth,
bar width=13pt,
symbolic x coords={A,B,C,D},
xtick = data,
enlarge x limits=0.25,
ymax=15,
ymin=0,
legend cell align=left,
legend style={
at={(1,1.05)},
anchor=south east,
column sep=1ex
}
]
\addplot[style={fill=red,mark=none}]
coordinates {(A, 4.44) (B,0.1) (C,4.37) (D,4.07)};
\addplot[style={fill=green,mark=none}]
coordinates {(A, 0.4) (B,0.8) (C,0.3) (D,0.5)};
\addplot[style={fill=blue,mark=none}]
coordinates {(A, 0.2) (B,0) (C,0.9) (D,0.8)};
\addplot[style={fill=yellow,mark=none}]
coordinates {(A, 9.59) (B,0.2) (C,8.86) (D,8.62)};
\legend{C1,C2,C3,C4}
\end{axis}
\end{tikzpicture}%
}}
\end{figure}
\end{document}