是否可以剪切/删除图表之外的所有“数据曲线”?(重叠的线)标题“ND”和“Formel”应该允许在外面。
该命令restrict x to domain=1000:10000000,
不起作用。另请参阅我的屏幕截图。谢谢。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}
\begin{semilogxaxis}
[
no marks, % Keine Punktmarkierungen der Datenpunkte (nur Linie plotten)
enlarge x limits=false, % x-Achse wird logarithmisch
title={Spannungskollektiv bei R=-1, $\sigma_{x}$}, % Titel
width=8cm, % Breite Diagramm
% height=7cm, % Höhe Diagramm
% scale only axis=false % Skalierung auf Basis inkl. Achsenbeschriftungen
grid=major, % none / minor / major
xmin=10000, xmax=100000000, % x: Darstellungsbereich
ymin=0, ymax=200, % y: Darstellungsbereich
xlabel={Lastzyklen N}, % x: Label
ylabel={Amplitude $\sigma_{a,x}$}, % y: Label
% extra y ticks = {110}, % Zusätzliche Markierungen auf der y-Achse
% extra y tick labels = {}, %Beschriftung Zusatz-ticks ausblenden
samples=50, % Auflösung der Funktionen
restrict y to domain=0:200,
%restrict x to domain=10000:100000000,
clip=false
]
\addplot+[const plot mark right,thin,blue] table[x=colcount,y=colamplitude] {
colamplitude colcount
142.387 1
142.387 50054
111.692 250266
107.619 300319
107.221 350372
105.793 550584
103.462 600637
98.2452 800849
};
\addplot+[red,thick,mark=none,domain=10000:1000000] {143.295225788333*(1000000/x)^(1/5)};
\addplot+[red,thin,dashed,mark=none,domain=1000000:1000000000] {143.295225788333*(1000000/x)^(1/5)};
\addplot+[red,thick,mark=none,domain=1000000:1000000000] {143.295225788333};
\node[red,left] at (axis cs:1000000,143.295225788333) {\footnotesize $ 143.3 $};
\draw[yellow!30!orange,thick] ({rel axis cs:1,0}|-{axis cs:0,15.8946951655}) -- ({rel axis cs:0,0}|-{axis cs:0,15.8946951655});
\draw[green!70!red,thick,dashed] ({axis cs:1000000,0}|-{rel axis cs:0,1}) -- ({axis cs:1000000,0}|-{rel axis cs:0,0});
\draw [green!70!red,very thick,restrict y to domain=0:200,](axis cs:0,110.1354266585) -- (axis cs:1000000,110.1354266585); % Horizontale Linie
\draw [green!70!red,very thick](axis cs:1000000,0) -- (axis cs:1000000,110.1354266585); % Vertikale Linie
\node[green!70!red,right] at (axis cs:1000000,110.1354266585) {\footnotesize $ \sigma_{\ddot{a}qu} = 110.1 $};
\node[blue,above right] at (axis cs:10000,142.387) {\footnotesize $ \sigma_{a,1} = 142.4 $};
\draw[green!60!red,ultra thick] ({axis cs:50000000,0}|-{rel axis cs:0,1}) --
({axis cs:50000000,0}|-{rel axis cs:0,0});
\draw[blue,thick] ({axis cs:60000000,30}) -- ({axis cs:600000000,100}) node[above,right] {Formel 2};
\draw[black!60!red,ultra thick] ({axis cs:1e6,0}|-{rel axis cs:0,1}) --
({axis cs:1e6,0}|-{rel axis cs:0,-0.3}) node [below] {$ND$};
\end{semilogxaxis}
\end{tikzpicture}
\end{document}
答案1
裁剪是最好的选择,因此设置clip=true
,但当然你也会裁剪你的标签。解决方案是在轴内定义标签的坐标,但在轴外进行绘制:
\documentclass{article}
\usepackage{pgfplots}
%\pgfplotsset{compat=1.14}
\begin{document}
\begin{tikzpicture}
\begin{semilogxaxis}
[
no marks, % Keine Punktmarkierungen der Datenpunkte (nur Linie plotten)
enlarge x limits=false, % x-Achse wird logarithmisch
title={Spannungskollektiv bei R=-1, $\sigma_{x}$}, % Titel
width=8cm, % Breite Diagramm
% height=7cm, % Höhe Diagramm
% scale only axis=false % Skalierung auf Basis inkl. Achsenbeschriftungen
grid=major, % none / minor / major
xmin=10000, xmax=100000000, % x: Darstellungsbereich
ymin=0, ymax=200, % y: Darstellungsbereich
xlabel={Lastzyklen N}, % x: Label
xlabel style={xshift = 2cm},
ylabel={Amplitude $\sigma_{a,x}$}, % y: Label
% extra y ticks = {110}, % Zusätzliche Markierungen auf der y-Achse
% extra y tick labels = {}, %Beschriftung Zusatz-ticks ausblenden
samples=50, % Auflösung der Funktionen
restrict y to domain=0:200,
%restrict x to domain=10000:100000000,
clip=true
]
\addplot+[const plot mark right,thin,blue] table[x=colcount,y=colamplitude] {
colamplitude colcount
142.387 1
142.387 50054
111.692 250266
107.619 300319
107.221 350372
105.793 550584
103.462 600637
98.2452 800849
};
\addplot+[red,thick,mark=none,domain=10000:1000000] {143.295225788333*(1000000/x)^(1/5)};
\addplot+[red,thin,dashed,mark=none,domain=1000000:1000000000] {143.295225788333*(1000000/x)^(1/5)};
\addplot+[red,thick,mark=none,domain=1000000:1000000000] {143.295225788333};
\node[red,left] at (axis cs:1000000,143.295225788333) {\footnotesize $ 143.3 $};
\draw[yellow!30!orange,thick] ({rel axis cs:1,0}|-{axis cs:0,15.8946951655}) -- ({rel axis cs:0,0}|-{axis cs:0,15.8946951655});
\draw[green!70!red,thick,dashed] ({axis cs:1000000,0}|-{rel axis cs:0,1}) -- ({axis cs:1000000,0}|-{rel axis cs:0,0});
\draw [green!70!red,very thick](axis cs:0,110.1354266585) -- (axis cs:1000000,110.1354266585); % Horizontale Linie
\draw [green!70!red,very thick](axis cs:1000000,0) -- (axis cs:1000000,110.1354266585); % Vertikale Linie
\node[green!70!red,right] at (axis cs:1000000,110.1354266585) {\footnotesize $ \sigma_{\ddot{a}qu} = 110.1 $};
\node[blue,above right] at (axis cs:10000,142.387) {\footnotesize $ \sigma_{a,1} = 142.4 $};
\draw[green!60!red,ultra thick] ({axis cs:50000000,0}|-{rel axis cs:0,1}) --
({axis cs:50000000,0}|-{rel axis cs:0,0});
\coordinate (Fa) at ({axis cs:60000000,30});
\coordinate (Fb) at ({axis cs:600000000,100});
\coordinate (NDa) at ({axis cs:1e6,0}|-{rel axis cs:0,1});
\coordinate (NDb) at ({axis cs:1e6,0}|-{rel axis cs:0,-0.3});
\end{semilogxaxis}
\draw[black!60!red,ultra thick] (NDa) -- node [pos=1,below] {$N\!D$} (NDb);
\draw[blue,thick] (Fa) -- (Fb) node[above,right] {Formel 2};
\end{tikzpicture}
\end{document}
答案2
thewaywewalk 呈现于他的回答使用方式clip=false
(这是 PGFPlots 中的默认方式)以及将轴区域“之外”的内容移到环境之外semilogxaxis
。这能可以做到,但缺点是你不能再使用轴坐标(例如)来放置东西,期望使用先定义 s 然后在周围环境中引用的axis cs:
解决方法。\coordinate
tikzpicture
另一种可能性是使用clip mode=individual
只剪切\addplot
命令内容的方法。我在这里使用了这种方法,因此无需在环境内tikzpicture
/环境外直接“绘制”任何东西semilogxaxis
。
除了这个要点之外,我注意到你做了很多事情,而且方式“非常复杂”。所以我重新组织了你的许多原始代码,以一种“更干净”(不一定更简单)的方式获得了几乎相同的结果。
有关详细信息,请查看代码中的注释
% used PGFPlots v1.14
\documentclass[border=5pt]{standalone}
\usepackage[utf8]{inputenc} % <-- added to be able to plot the "ä"
\usepackage{amsmath} % <-- added to have the `\text' command
\usepackage{pgfplots}
\pgfplotsset{
compat=1.11,
}
\begin{document}
\begin{tikzpicture}[
/tikz/declare function={
% moved definitions of axis limits here for later use
% (also changed to scientific format which is much simpler to check)
xmin=1e4;
xmax=1e8;
ymin=0;
ymax=200;
% also declare some other "reused" values here as variables
% (please rename them to something more useful)
Blue=142.387;
Red=143.295225788333;
Yellow=15.8946951655;
Green=110.1354266585;
},
% create a style for the (value) labels
Node/.style={
font=\footnotesize,
/pgf/number format/.cd,
% show numbers with one digit after the decimal separator
precision=1,
% and use a comma as decimal separator
use comma,
},
]
\begin{semilogxaxis}[
width=8cm,
% used above declared variables for the axis limits
xmin=xmin,
xmax=xmax,
ymin=ymin,
ymax=ymax,
xlabel={Anzahl Lastzyklen $N$},
ylabel={Amplitude $\sigma_{a,x}$},
enlarge x limits=false,
grid=major,
title={Spannungskollektiv bei $R = -1$, $\sigma_{x}$},
% move title a bit up, so the (new) "ND" label has enough room
title style={
yshift=1ex,
},
% % this is a `tikz' option ...
% no marks,
% this is the `pgfplots' option
% (and with that you don't have to write "mark=none" at every `\addplot'
no markers,
samples=50,
% =================================================================
% these are not needed any more when you use the newly added option
% restrict y to domain=0:200,
% clip=false,
clip mode=individual,
% =================================================================
]
% ---------------------------------------------------------------------
% addplots
\addplot+ [
const plot mark right,
thin,
blue,
] table [x=colcount,y=colamplitude] {
colamplitude colcount
142.387 1
142.387 50054
111.692 250266
107.619 300319
107.221 350372
105.793 550584
103.462 600637
98.2452 800849
};
\addplot+ [
red,
thick,
domain=1e4:1e6,
] {Red*(1000000/x)^(1/5)};
\addplot+ [
red,
thin,
dashed,
domain=1e6:1e8,
] {Red*(1000000/x)^(1/5)};
\addplot+ [
red,
thick,
mark=none,
domain=1e6:1e8,
] {Red}
% use the `Node' style here
node [pos=0,left,font=\footnotesize]
% also don't state the number itself again and again.
% Declare it as a variable and then use this instead.
% Then you need to change only *one* point to adapt the
% lines position as well as the corresponding label
{\pgfmathparse{Red}\pgfmathprintnumber{\pgfmathresult}}
;
% ---------------------------------------------------------------------
% lines + labels
\draw [yellow!30!orange,thick]
% % way to complicated ...
% ({rel axis cs:1,0}|-{axis cs:0,15.8946951655})
% -- ({rel axis cs:0,0}|-{axis cs:0,15.8946951655});
% ... much simpler is
(xmin,Yellow) -- (xmax,Yellow);
\node [blue,above right,Node] at (xmin,Blue)
{$\sigma_{a,1} = \pgfmathparse{Blue}
\pgfmathprintnumber{\pgfmathresult}$};
\draw [green!70!red,thick,dashed] (1e6,ymin) -- (1e6,ymax);
% horizontal + vertical line
\draw [
green!70!red,
very thick,
% this should have caused an error, because you are trying to
% use a PGFPlots option in a TikZ command
% (which isn't very useful)
% restrict y to domain=0:200,
] (xmin,Green) -- (1e6,Green) -- (1e6,ymin)
node [pos=0,right,Node]
{$\sigma_{\text{äqu}} = \pgfmathparse{Green}
\pgfmathprintnumber{\pgfmathresult}$}
;
\draw [green!60!red,ultra thick] (5e7,ymin) -- (5e7,ymax);
% I moved the label above the plot, where it doesn't cross the
% tick label and the axis label
\draw [black!60!red,ultra thick]
(1e6,ymin) -- (1e6,ymax)
node [above,font=\footnotesize] {$\mathit{ND}$};
% % again this is a very complicated way to state this ...
% \draw [blue,thick]
% ({axis cs:60000000,30}) -- ({axis cs:600000000,100})
% node [above,right] {Formel 2};
% ... how about
\node [
coordinate,
pin={
[%
pin edge={
blue,
thin,
},
blue,
% % if you want the pin a bit longer
% pin distance=10ex,
]above right:Formel 2%
},
] at (6e7,30) {};
\end{semilogxaxis}
\end{tikzpicture}
\end{document}