我从 GeoGebra 导出了一些代码,但出现错误“尺寸太大”。我已将错误范围缩小到这两行
\draw [samples=50,domain=-0.99:0.99,rotate around={0.:(0.,0.)},xshift=0.cm,yshift=0.cm,line width=1.2pt] plot ({1.*(1+(\x)^2)/(1-(\x)^2)},{4.*2*(\x)/(1-(\x)^2)});
\draw [samples=50,domain=-0.99:0.99,rotate around={0.:(0.,0.)},xshift=0.cm,yshift=0.cm,line width=1.2pt] plot ({1.*(-1-(\x)^2)/(1-(\x)^2)},{4.*(-2)*(\x)/(1-(\x)^2)});
我该怎么做才能解决这个问题?完整代码如下:
\documentclass[11pt]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.6666666666666667cm,y=0.625cm]
\tikzset{every pin edge/.style={thin}}
\begin{axis}[
x=1.667cm,y=0.625cm,
restrict x to domain*=-3:3,
restrict y to domain*=-1:7,
axis lines=middle,
ymajorgrids=true,
xmajorgrids=true,
xmin=-3.0,
xmax=3.0,
ymin=-1.0,
ymax=7.0,
xtick={-3.0,-2.0,...,3.0},
ytick={-1.0,0.0,...,7.0},]
\draw [samples=50,domain=-0.99:0.99,rotate around={0.:(0.,0.)},xshift=0.cm,yshift=0.cm,line width=1.2pt] plot ({1.*(1+(\x)^2)/(1-(\x)^2)},{4.*2*(\x)/(1-(\x)^2)});
\draw [samples=50,domain=-0.99:0.99,rotate around={0.:(0.,0.)},xshift=0.cm,yshift=0.cm,line width=1.2pt] plot ({1.*(-1-(\x)^2)/(1-(\x)^2)},{4.*(-2)*(\x)/(1-(\x)^2)});
\draw [line width=0.4pt,domain=-3.:3.] plot(\x,{(-4.250947801416127-3.538296784708813*\x)/-2.387670622927252});
\draw [line width=0.4pt,domain=-3.:3.] plot(\x,{(--9.300005586137612-4.239726050759403*\x)/2.861000632961514});
\draw [line width=0.4pt,domain=-3.:3.] plot(\x,{(-4.250947801416127-3.538296784708813*\x)/-2.387670622927252});
\draw [line width=0.4pt,domain=-3.:3.] plot(\x,{(-4.250947801416127-3.538296784708813*\x)/-2.387670622927252});
\draw [line width=0.4pt,domain=-3.:3.] plot(\x,{(--9.300005586137612-4.239726050759403*\x)/2.861000632961514});
\draw [line width=.4pt,dash pattern=on 5pt off 5pt] (0.5,-1.) -- (0.5,7.);
\addplot[mark=*, color=black] coordinates {(-1.7794648702694271,5.887607628941302)} node[pin={[ultra thick,pin distance=10pt]0:{$A$}}]{};
\addplot[mark=*, color=black] coordinates {(1.384964676131416,3.8327580756041426)} node[pin={[ultra thick,pin distance=10pt]135:{$Q$}}]{};
\addplot[mark=*, color=black] coordinates {(1.081535762692087,1.647881578181899)} node[pin={[ultra thick,pin distance=10pt]0:{$B$}}]{};
\addplot[mark=*, color=black] coordinates {(-1.0027059467958361,0.2944612908953296)} node[pin={[ultra thick,pin distance=10pt]160:{$P$}}]{};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
我将按照以下方式绘制您的图表:
\documentclass[11pt, border=3.141592]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16} % recent is 1.18
\usetikzlibrary{intersections}
\usepackage{mathrsfs}
\begin{document}
\begin{tikzpicture}[
dot/.style = {circle, fill, semitransparent, inner sep=2pt},
every pin/.style = {pin edge={black, shorten <=1pt}, pin distance=10pt}
]
\begin{axis}[
x=1.667cm,y=0.625cm,
axis lines=middle,
xmin=-3, xmax=3,
ymin=-1, ymax=7,
ytick={-1,0,...,7},
axis on top,
grid,
ticklabel style = {font=\scriptsize},
domain=-3:3, samples=101, no marks,
]
\addplot [red, thick, name path=A1] ({+sqrt(1+\x*\x)},4*\x);
\addplot [red, thick, name path=A2] ({-sqrt(1+\x*\x)},4*\x);
%
\addplot [blue, name path=B1] coordinates {(-1.9,-1) (3.0, 6.2)};
\addplot [blue, name path=B2] coordinates {(-2.5, 7) (2.8,-1.0)};
%
\draw[dash pattern=on 5pt off 5pt] (0.5,-1) -- (0.5,7.);
%
\path [name intersections={of=A2 and B2, by=x}]
node[dot, pin=180:$A$] at (x) {};
\path [name intersections={of=A2 and B1, by=x}]
node[dot, pin=180:$P$] at (x) {};
\path [name intersections={of=A1 and B1, by=x}]
node[dot, pin= 0:$Q$] at (x) {};
\path [name intersections={of=A1 and B2, by=x}]
node[dot, pin= 0:$B$] at (x) {};
%\node[dot, pin=180:$A$] at (-1.779464870269427, 5.887607628941301) {};
%\node[dot, pin= 0:$Q$] at ( 1.384964676131416, 3.832758075604143) {};
%\node[dot, pin= 0:$B$] at ( 1.081535762692087, 1.647881578181899) {};
\end{axis}
\end{tikzpicture}
\end{document}
导致错误的原因在于函数的绘制方式。如果用draw plot ...
编译替换addplot
,结果会很好,但结果会出错(由于函数的定义)。因此,我用平方根函数重新定义/近似你的函数,并单独绘制线条。它们的交点由库的帮助确定intersections
。