Unvollständiges Diagramm in pgfplots

Unvollständiges Diagramm in pgfplots

Ich versuche, die mögliche Menge eines Maximierungsproblems darzustellen. Eine der Einschränkungen ist unvollständig, da sie sich bis zur x-Achse erstrecken sollte.Bildbeschreibung hier eingeben

Außerdem vermute ich, dass die centerUmgebung dazu führt, dass die gesamte Abbildung samt Beschriftung in Bezug auf die Seite zentriert wird, aber ich hatte erwartet, dass die Abbildung auch in Bezug auf die Beschriftung zentriert wird.

Das MWE ist

\documentclass[a4paper]{article}
\usepackage[font=footnotesize,labelfont=bf]{caption}
\usepackage{pgfplots}

\pgfplotsset{compat = newest}

\begin{document}

\begin{center}
   \begin{figure}
      \begin{tikzpicture}
         \begin{axis}[
            ticks=none, 
            axis x line=bottom,
            axis y line=left,
            xmin=0,xmax=1.2,
            ymin=0,ymax=1.3]
         \addplot[
            domain = 0:sqrt(33/56),
            samples =200,
            smooth,
            blue,
            thick
            ] {sqrt((33/8-7*x^2)/3)};
         \end{axis}
      \end{tikzpicture}
      \caption{This is text just to show that the figure is not centered with respect to the caption.}
   \end{figure}
\end{center} 

\end{document}

Antwort1

Erweiterung der Antwort von @RaffaeleSantoro:

Die Verwendung samples = 800hilft.

Fügen Sie es außerdem nicht figurein eine centerUmgebung ein, sondern verwenden Sie \centering„inside“ figurewie folgt:

\documentclass[a4paper]{article}
\usepackage[font=footnotesize,labelfont=bf]{caption}
\usepackage{pgfplots}

\pgfplotsset{compat = newest}

\begin{document}

\begin{figure}
    \centering
    \begin{tikzpicture}
        \begin{axis}[
        ticks=none, 
        axis x line=bottom,
        axis y line=left,
        xmin=0,xmax=1.2,
        ymin=0,ymax=1.3]
        \addplot[
        domain = 0:sqrt(33/56),
        samples =800,
        smooth,
        blue,
        thick
        ] {sqrt((33/8-7*x^2)/3)};
        \end{axis}
    \end{tikzpicture}
    \caption{This is text just to show that the figure is not centered with respect to the caption.}
\end{figure}

\end{document}

Bildbeschreibung hier eingeben

Antwort2

Dies liegt nicht daran, dass der letzte Punkt nicht „erreicht“ wurde. Die Funktion ist rechts von nicht definiert sqrt(33/56)und mit der endlichen Genauigkeit eines Computers ist es auch nicht möglich, die Funktion auszuwerten sqrt(33/56). - Der Punkt wird verworfen – sehen Sie sich das Kompilierungsprotokoll an. Eine Möglichkeit besteht darin, die Anzahl der Samples enorm zu erhöhen, sodass der vorletzte Punkt ein akzeptables Ergebnis liefert. Eine andere Möglichkeit besteht darin, den Punkt separat mit einem zu definieren y filter. So:

\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ticks=none, 
axis x line=bottom,
axis y line=left,
xmin=0,xmax=1.2,
ymin=0,ymax=1.3]
\addplot[
domain=0:sqrt(33/56),
samples=200,
smooth,
blue, thick,
y filter/.expression={x==sqrt(33/56)?0:y},
] {sqrt((33/8-7*x^2)/3)};
\end{axis}
\end{tikzpicture}
\end{document}

Viertelkreis im Diagramm

verwandte Informationen