这是我目前的图表:
1:所以我想标记我的X和是轴标签带有浅灰色盒子。
2:我想创建一个额外的标签。(这应该是我矩形的高度,在我们的案例中值为 18)用红色书写,并带有浅红色填充框。谢谢。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usetikzlibrary{patterns}
\pgfplotsset{%
every axis title/.append style={font=\mdseries},
every label/.append style={font=\bfseries\boldmath},
every axis/.append style={font=\bfseries\boldmath}
}
\begin{document}
\begin{tikzpicture}
\begin{semilogxaxis}
[
enlarge x limits=false,
no marks,
grid=none,
xmin=1e4, xmax=1e8,
ymin=0, ymax=150,
title= Amplituden Spektrum $\sigma_{x}$,
ylabel={$\sigma_{a}$},
xlabel={$N$},
grid =none, %Hauptgitter grid = minor, %
extra y ticks = {35},
%extra y tick labels = {}, %Beschriftung weg
samples=50, %Function (red curve)
domain=0.125:1e6, %Function (red curve)
]
%\addplot+[const plot] table[x=countb,y=amplitudea] {3.dat}; %step stairs
\addplot+[draw=red,mark=none,domain=1e5:1e6,dashed] {100*(1e6/x)^(1/5)};
\draw[orange,dashed] ({axis cs:50045,0}|-{rel axis cs:0,1}) -- ({axis cs:50045,0}|-{rel axis cs:0,0});
\draw[dashed,green] ({rel axis cs:1,0}|-{axis cs:0,34.385735235}) -- ({rel axis cs:0,0}|-{axis cs:0,34.385735235});
\draw [draw=red,thick] (rel axis cs:0,0) rectangle (axis cs:100000,18.385735235);
\addplot+[domain=1e6:1e7,no marks] {100};
%********
%********
\end{semilogxaxis}
\end{tikzpicture}
\end{document}
答案1
要格式化 x 和 y 刻度标签,请使用键x tick label style
和y tick label style
。要添加红色数字 18,请使用\node
带有环境坐标系中坐标的命令axis
。
\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usetikzlibrary{patterns}
\pgfplotsset{%
every axis title/.append style={font=\mdseries},
every label/.append style={font=\bfseries\boldmath},
every axis/.append style={font=\bfseries\boldmath}
}
\begin{document}
\begin{tikzpicture}
\begin{semilogxaxis}
[enlarge x limits=false,
no marks,
grid=none,
xmin=1e4, xmax=1e8,
ymin=0, ymax=150,
title= Amplituden Spektrum $\sigma_{x}$,
xlabel={$N$},
ylabel={$\sigma_{a}$},
x tick label style={fill=gray!20}, %<<<<<<<<<<<
y tick label style={fill=gray!20}, %<<<<<<<<<<<
grid =none,
extra y ticks = {35},
samples=50,
domain=0.125:1e6
]
\addplot+[draw=red,mark=none,domain=1e5:1e6,dashed] {100*(1e6/x)^(1/5)};
\draw[orange,dashed] ({axis cs:50045,0}|-{rel axis cs:0,1})
-- ({axis cs:50045,0}|-{rel axis cs:0,0});
\draw[dashed,green] ({rel axis cs:1,0}|-{axis cs:0,34.385735235})
-- ({rel axis cs:0,0}|-{axis cs:0,34.385735235});
\draw[draw=red,thick] (rel axis cs:0,0) rectangle (axis cs:100000,18.385735235);
\addplot+[domain=1e6:1e7,no marks] {100};
\node[fill=red!20,text=red] at (axis cs:20000,10) {18}; %<<<<<<<<<<<
\end{semilogxaxis}
\end{tikzpicture}
\end{document}
答案2
在semilogaxis
环境中,添加以下行
ticklabel style={fill=gray!50},
使你的刻度线具有灰色背景。阴影可以从 50% 灰色调整为更浅或更深的颜色。你将遇到垂直刻度线与0
水平刻度线重叠的问题10^4
。
semilogaxis
要在环境之外但仍在环境内添加额外的红色节点,tikzpicture
请添加以下行
\node[fill=red!20] at (.4,.4) {\color{red}{\textsf{18}}};
在您指定的位置(大约)添加一个节点。我已将字体设为无衬线字体,因为它看起来就是您想要的。您可以通过删除命令将其恢复为常规数学字体\textsf
。