pgfplots - 函数未达到 x 轴

pgfplots - 函数未达到 x 轴

我无法使用函数到达 x 轴。没有人知道如何解决这个问题吗? 在此处输入图片描述

%%%%%%%%%%%%%%%%%% INTRODUCTION %%%%%%%%%%%%%%%%%%
\documentclass[]{standalone}
%%%%%%%%%%%%%%%%%% INPUT %%%%%%%%%%%%%%%%%%
%\input{preamble.tex}
%\input{parameters.tex}
%%%%%%%%%%%%%%%%%% PACKAGE %%%%%%%%%%%%%%%%%%
\usepackage{tikz, tkz-euclide}%  permet de dessiner des figures, des graphiques
\usetikzlibrary{%
    matrix,
    arrows,
    arrows.meta,
    bending,
    calc,
    math,
    shapes,
    backgrounds,
    decorations.markings,
    }

\usepackage{pgfplots}
%%  FONT
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
%
\usepackage{tgadventor}% paquet de police de caractère TGadventor
\usepackage{sansmath}%  Copie-colle la police active dans 
%                       \sfdefault (/!\ N'EST PAS UNE POLICE DE CARACTÈRES)
\usepackage{xcolor}

\tikzset{%
    graphpgf/.style={%
        font={\sansmath\sffamily\Large}, 
        line cap=round, line join=round, 
        >={Latex[length=3mm]}, 
        x=1.0cm, y=1.0cm, 
        background rectangle/.style={fill=white, shift={(-5pt,-5pt)}},
        show background rectangle,
        inner frame sep=10pt
    }
}

\pgfplotsset{%
    /pgfplots/graphxy/.style={%
        %%%%%%%%%%  Dimensionnement de l'image  %%%%%%%%%%
        width=13.5cm,
        height=13.5cm,
        unit vector ratio=1 1 1,
        %%%%%%%%%%  esthétique des axes  %%%%%%%%%%
        xlabel=$\mathrm{x}$,         ylabel=$\mathrm{y}$,
        axis lines = middle,
        enlargelimits=false,
        line width=0.4mm,
        every major grid/.append style={black!20, line width=0.35mm,},
        every minor grid/.append style={black!15, line width=0.15mm,},
        every major tick/.append style={line width=0.4 mm, major tick length=7pt, black},
        every minor tick/.append style={line width=0.15mm, minor tick length=4pt, black},
        %axis background/.style={fill=white},
        grid=both,
        axis line style = {shorten >=-12.5pt, shorten <=-12.5pt, -{Latex[length=3mm]}},
        xlabel style={at={(ticklabel* cs:1)},yshift=-3.5pt, anchor=north west, font=\sansmath\sffamily\Large},
        ylabel style={at={(ticklabel* cs:1)},xshift=-3.5pt, anchor=south east, font=\sansmath\sffamily\Large},
        title style = {font=\sansmath\sffamily\Large, align=center, inner sep=12pt,},
        extra x ticks={0},
        extra x tick style={%
            grid= none,
            xticklabel style={%
                below right,
            },
            every major tick/.append style={%
                scale=1,
                draw=none,
                postaction={decorate},
                decoration={%
                    markings,
                    mark=between positions 3.5pt and 1 step 7pt with{%
                      \draw[fill] (0, 0) circle (1.5pt);
                    },
                },
            },
        },
    }
}
%%%%%%%%%%%%%%%%%% DOCUMENT %%%%%%%%%%%%%%%%%%
\begin{document}
\begin{tikzpicture}[graphpgf]

%%%%%%%%%%%%%%%%%% Data Table %%%%%%%%%%%%%%%%%%
    \begin{axis}[%
        graphxy,
        %minor tick num=1,
        %%%     Axe x
        xmin=-5-0.3, xmax=5+0.3,
        xtick={-100,-99,...,100},
        %xticklabels=(,-6,,-4,,-2,,),
        %minor xtick={-10,...,8},
        %domain=-6:6,
        %%%     Axe x
        ymin=-2-0.3,ymax=8+0.3,
        ytick={-100,-99,...,100},
        %minor ytick={-8,...,8},
        %restrict y to domain=-3:7,
               ]%
                \addplot[%
                    color=orange,
                    opacity=0.8,
                    line width=0.4mm,
                    samples =2048,
                    domain=-4.606715:1.356715,
                    restrict y to domain=-0.00001:5.9635,
                    smooth,
                    ]%
                    {sqrt(-4* x^2 -13 * x +25)}
                    %node [right , pos=0.04, scale=1.2] {f(x)}
                ;
        ;
    \end{axis}
\end{tikzpicture}
\end{document}

我时不时会遇到这个问题,而且总是费力地寻找解决方案。您有什么建议吗?

答案1

您需要一个最小工作示例:我刚刚被要求写一个最小工作示例(MWE),那是什么?

我不知道您想通过选项domain=-4.606715:1.356715和获得什么restrict y to domain=-0.00001:5.9635。人们通常会对这些选项使用整数。

对于对称图,您需要奇数个样本。我不知道如何让末端从准确正确的点开始,但您可以通过将末端向下拉来作弊,当它们足够小时,如下所示y filter

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
  grid=major,
  xmin=-5, xmax=3,
  ymin=-2, ymax=8,
]%
\addplot[%
  orange,
  samples=2047,
  domain=-5:2,
  smooth,
  y filter/.expression={y<0.1 ? 0 : y}
]%
   {sqrt(-4* x^2 -13 * x +25)};
\end{axis}
\end{tikzpicture}
\end{document}

图形以 y=0 开始和结束

相关内容