在 X 标签周围添加文字

在 X 标签周围添加文字

图1由Matlab生成,以下代码使用Matlabmatlab2tikz包生成。图1和图2的不同之处在于符号的位置%。图2是使用 转换图1的代码生成的matlab2tikz

\documentclass{article}
\usepackage{pgfplots}
\usepackage{subfig}
\usepackage{float}
\pagestyle{empty}
\pgfplotsset{compat=newest}
\pgfplotsset{plot coordinates/math parser=false}
\newlength\figureheight
\newlength\figurewidth
\begin{document}

\definecolor{mycolor1}{rgb}{1,0,1}
\definecolor{mycolor2}{rgb}{0,0.498039215803146,0}
\definecolor{mycolor3}{rgb}{0.600000023841858,0.200000002980232,0}

\begin{tikzpicture}

\begin{axis}[%
width=4.52083333333333in,
height=3.565625in,
scale only axis,
xmin=1,
xmax=7,
ymin=0,
ymax=1,
axis x line*=bottom,
axis y line*=left
]
\addplot [
color=black,
solid,
line width=1.5pt,
mark size=2.8pt,
mark=square*,
mark options={solid,fill=black},
forget plot
]
table[row sep=crcr]{
1 0.0596188675796392\\
2 0.167927145682257\\
3 0.471088374541939\\
4 0.500471624154843\\
5 0.681971904149063\\
6 0.712694471678914\\
7 0.978680649641159\\
};
\addplot [
color=red,
solid,
line width=1.5pt,
mark size=4.0pt,
mark=*,
mark options={solid,fill=red},
forget plot
]
table[row sep=crcr]{
1 0.0424311375007417\\
2 0.0714454646006424\\
3 0.096730025780867\\
4 0.521649842464284\\
5 0.722439592366842\\
6 0.817547092079286\\
7 0.818148553859625\\
};
\addplot [
color=blue,
solid,
line width=1.5pt,
mark size=2.7pt,
mark=triangle*,
mark options={solid,fill=blue},
forget plot
]
table[row sep=crcr]{
1 0.149865442477967\\
2 0.453797708726919\\
3 0.518594942510538\\
4 0.648991492712356\\
5 0.659605252908307\\
6 0.800330575352401\\
7 0.972974554763863\\
};
\addplot [
color=mycolor1,
solid,
line width=1.5pt,
mark size=2.7pt,
mark=triangle*,
mark options={solid,,rotate=180,fill=mycolor1},
forget plot
]
table[row sep=crcr]{
1 0.083469814858914\\
2 0.133171007607162\\
3 0.173388613119006\\
4 0.390937802323736\\
5 0.432391503783462\\
6 0.825313795402046\\
7 0.83137974283907\\
};
\addplot [
color=mycolor2,
solid,
line width=1.5pt,
mark size=2.7pt,
mark=triangle*,
mark options={solid,,rotate=270,fill=mycolor2},
forget plot
]
table[row sep=crcr]{
1 0.0604711791698936\\
2 0.399257770613576\\
3 0.416799467930787\\
4 0.526875830508296\\
5 0.627973359190104\\
6 0.656859890973707\\
7 0.80336439160244\\
};
\addplot [
color=mycolor3,
solid,
line width=1.5pt,
mark size=2.7pt,
mark=triangle*,
mark options={solid,,rotate=90,fill=mycolor3},
forget plot
]
table[row sep=crcr]{
1 0.015487125636019\\
2 0.106216344928664\\
3 0.167168409914656\\
4 0.291984079961715\\
5 0.372409740055537\\
6 0.43165117024872\\
7 0.984063724379154\\
};
\node[right, inner sep=0mm, text=black] at (axis cs:6.7, 0.05) {(\%)};
\end{axis}
\end{tikzpicture}%


\end{document} 

我想将%符号放置在图 2 中,就像图 1 中一样。任何建议都将不胜感激!

图。1

图2

答案1

另一个选项是将 添加%xlabel,并通过添加更改此 的位置

xlabel={(\%)},
xlabel style={at={(rel axis cs:1.01,0)},anchor=west}

axis选项。rel axis cs是一个相对于轴的坐标系,其中 (0,0) 位于左下角,(1,1) 位于右上角。

要将标签稍微向下移动,您可以将锚点更改为north west,如Jake的回答中所述,或添加到yshift=<negative length>xlabel stylexlabel style={at={(rel axis cs:1.01,0)},anchor=north west}xlabel style={at={(rel axis cs:1.01,0)},anchor=west,yshift=-1.5ex}

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\pgfplotsset{plot coordinates/math parser=false}
\begin{document}

\definecolor{mycolor1}{rgb}{1,0,1}
\definecolor{mycolor2}{rgb}{0,0.498039215803146,0}
\definecolor{mycolor3}{rgb}{0.600000023841858,0.200000002980232,0}

\begin{tikzpicture}

\begin{axis}[%
width=4.52083333333333in,
height=3.565625in,
scale only axis,
xmin=1,
xmax=7,
ymin=0,
ymax=1,
axis x line*=bottom,
axis y line*=left,
xlabel={(\%)},
xlabel style={at={(rel axis cs:1.01,0)},anchor=west}
]
\addplot [
color=black,
solid,
line width=1.5pt,
mark size=2.8pt,
mark=square*,
mark options={solid,fill=black},
forget plot
]
table[row sep=crcr]{
1 0.0596188675796392\\
2 0.167927145682257\\
3 0.471088374541939\\
4 0.500471624154843\\
5 0.681971904149063\\
6 0.712694471678914\\
7 0.978680649641159\\
};
\addplot [
color=red,
solid,
line width=1.5pt,
mark size=4.0pt,
mark=*,
mark options={solid,fill=red},
forget plot
]
table[row sep=crcr]{
1 0.0424311375007417\\
2 0.0714454646006424\\
3 0.096730025780867\\
4 0.521649842464284\\
5 0.722439592366842\\
6 0.817547092079286\\
7 0.818148553859625\\
};
\addplot [
color=blue,
solid,
line width=1.5pt,
mark size=2.7pt,
mark=triangle*,
mark options={solid,fill=blue},
forget plot
]
table[row sep=crcr]{
1 0.149865442477967\\
2 0.453797708726919\\
3 0.518594942510538\\
4 0.648991492712356\\
5 0.659605252908307\\
6 0.800330575352401\\
7 0.972974554763863\\
};
\addplot [
color=mycolor1,
solid,
line width=1.5pt,
mark size=2.7pt,
mark=triangle*,
mark options={solid,,rotate=180,fill=mycolor1},
forget plot
]
table[row sep=crcr]{
1 0.083469814858914\\
2 0.133171007607162\\
3 0.173388613119006\\
4 0.390937802323736\\
5 0.432391503783462\\
6 0.825313795402046\\
7 0.83137974283907\\
};
\addplot [
color=mycolor2,
solid,
line width=1.5pt,
mark size=2.7pt,
mark=triangle*,
mark options={solid,,rotate=270,fill=mycolor2},
forget plot
]
table[row sep=crcr]{
1 0.0604711791698936\\
2 0.399257770613576\\
3 0.416799467930787\\
4 0.526875830508296\\
5 0.627973359190104\\
6 0.656859890973707\\
7 0.80336439160244\\
};
\addplot [
color=mycolor3,
solid,
line width=1.5pt,
mark size=2.7pt,
mark=triangle*,
mark options={solid,,rotate=90,fill=mycolor3},
forget plot
]
table[row sep=crcr]{
1 0.015487125636019\\
2 0.106216344928664\\
3 0.167168409914656\\
4 0.291984079961715\\
5 0.372409740055537\\
6 0.43165117024872\\
7 0.984063724379154\\
};
\end{axis}
\end{tikzpicture}%


\end{document} 

在此处输入图片描述

答案2

您可以使用以下方式放置节点\node[anchor=north west, text height=1.5ex, xshift=0.5em] at (rel axis cs:1,0) {(\%)}; axis环境之外(否则标签会被剪掉),或者

xticklabel style={text height=1.5ex},
after end axis/.code={
    \node[anchor=north west, text height=1.5ex, xshift=0.5em] at (rel axis cs:1,0) {(\%)};
}

(给出的代码after end axis/.code未被剪辑)。

请注意,您必须text height为新节点和现有刻度标签指定,否则对齐将会关闭(由于括号的高度大于数字)。

锚点current axis.right of origin指的是 x 轴线的尖端。

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}

\definecolor{mycolor1}{rgb}{1,0,1}
\definecolor{mycolor2}{rgb}{0,0.498039215803146,0}
\definecolor{mycolor3}{rgb}{0.600000023841858,0.200000002980232,0}

\begin{tikzpicture}

\begin{axis}[%
width=4.52083333333333in,
height=3.565625in,
scale only axis,
xmin=1,
xmax=7,
ymin=0,
ymax=1,
axis x line*=bottom,
axis y line*=left,
xticklabel style={text height=1.5ex},
after end axis/.code={
    \node[anchor=north west, text height=1.5ex, xshift=0.5em] at (rel axis cs:1,0) {(\%)};
}
]
\addplot [
color=black,
solid,
line width=1.5pt,
mark size=2.8pt,
mark=square*,
mark options={solid,fill=black},
forget plot
]
table[row sep=crcr]{
1 0.0596188675796392\\
2 0.167927145682257\\
3 0.471088374541939\\
4 0.500471624154843\\
5 0.681971904149063\\
6 0.712694471678914\\
7 0.978680649641159\\
};
\addplot [
color=red,
solid,
line width=1.5pt,
mark size=4.0pt,
mark=*,
mark options={solid,fill=red},
forget plot
]
table[row sep=crcr]{
1 0.0424311375007417\\
2 0.0714454646006424\\
3 0.096730025780867\\
4 0.521649842464284\\
5 0.722439592366842\\
6 0.817547092079286\\
7 0.818148553859625\\
};
\addplot [
color=blue,
solid,
line width=1.5pt,
mark size=2.7pt,
mark=triangle*,
mark options={solid,fill=blue},
forget plot
]
table[row sep=crcr]{
1 0.149865442477967\\
2 0.453797708726919\\
3 0.518594942510538\\
4 0.648991492712356\\
5 0.659605252908307\\
6 0.800330575352401\\
7 0.972974554763863\\
};
\addplot [
color=mycolor1,
solid,
line width=1.5pt,
mark size=2.7pt,
mark=triangle*,
mark options={solid,,rotate=180,fill=mycolor1},
forget plot
]
table[row sep=crcr]{
1 0.083469814858914\\
2 0.133171007607162\\
3 0.173388613119006\\
4 0.390937802323736\\
5 0.432391503783462\\
6 0.825313795402046\\
7 0.83137974283907\\
};
\addplot [
color=mycolor2,
solid,
line width=1.5pt,
mark size=2.7pt,
mark=triangle*,
mark options={solid,,rotate=270,fill=mycolor2},
forget plot
]
table[row sep=crcr]{
1 0.0604711791698936\\
2 0.399257770613576\\
3 0.416799467930787\\
4 0.526875830508296\\
5 0.627973359190104\\
6 0.656859890973707\\
7 0.80336439160244\\
};
\addplot [
color=mycolor3,
solid,
line width=1.5pt,
mark size=2.7pt,
mark=triangle*,
mark options={solid,,rotate=90,fill=mycolor3},
forget plot
]
table[row sep=crcr]{
1 0.015487125636019\\
2 0.106216344928664\\
3 0.167168409914656\\
4 0.291984079961715\\
5 0.372409740055537\\
6 0.43165117024872\\
7 0.984063724379154\\
};

\end{axis}
\end{tikzpicture}%


\end{document} 

相关内容