如何绘制以下图表

如何绘制以下图表

我是 LaTeX 的新手,正在学习绘图​​,我想绘制$y=x^2$在哪里xmin=0ymin=0但是我不想在轴上使用数字点,而是需要(k,0)和(0,k)以及连接这两个点的一条线,并使矩形也与图形相交$y=x^2$

答案1

我很喜欢pgf图

从这个开始怎么样:

编辑:进行小改进,但不要太复杂

在此处输入图片描述

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    small,
    axis lines=center,
    xmin=0,ymin=0,
    domain=0:1.5,
    xtick=\empty,
    ytick=\empty,
    no markers,
    extra x ticks={1},
    extra x tick labels={${(k,0)}$},
    extra y ticks={1},
    extra y tick labels={${(0,k)}$},
    ]
\addplot {x^2};
\addplot coordinates {(1,0)(1,1)(0,1)};
\end{axis}
\end{tikzpicture}
\end{document}

答案2

像这个:

在此处输入图片描述

使用以下代码:

\documentclass[tikz, border=1cm]{standalone}

\begin{document}
    \begin{tikzpicture}
    \draw[gray!15,step=.5] (-.5,-.5) grid (3.5,9.5);
    \draw[thin,->] (-.5,0)--(3.5,0) node[above] () {$x$};
    \draw[thin,->] (0,-.5)--(0,9.5) node[above] () {$y$};
    \draw[domain=0:3, smooth, variable=\x, line width=2pt, blue] plot ({\x}, {\x*\x});
    \draw[red,thin] (2.8,0) rectangle (0,2.8);
    \end{tikzpicture}

\end{document}

答案3

R 图并非设计为模仿 pfgplots 样式,因此用箭头和自定义刻度标签绘制轴会破坏代码的简单性,但仅供记录,example.Rnw使用knitr

姆韦

\documentclass[twocolumn]{article}
\begin{document}
<<dev='tikz',echo=F,fig.width=3.5,fig.height=3.5>>=
x=seq(0,10,.1)
y=x^2
xlim <- c(min(x),max(x));
ylim <- c(min(y),max(y));
plot(x,y,type = "l", lty = 1, axes = F, frame = F,col="blue",xlab="",ylab="",xlim=xlim,ylim=ylim) 
axis(1, mgp=c(0,-.5,0), las=1, tick=F, at =5,label="(k,0)")
axis(2, mgp=c(0,-.5,0), las=2, tick=F, at =5^2,label="(0,k)")
mtext('y',3,1,at=0,las=1); ## y label
mtext('x',4,1,at=0,las=1); ## x label
segments(x0 =5, y0 =0, x1 =5, y1 =5^2, col = "red") 
segments(x0 =0, y0 =5^2, x1 =5, y1 =5^2, col = "red") 
arrows(c(0,xlim[1]),c(ylim[1],0),c(0,xlim[2]),c(ylim[2],0),0.05)
@
\end{document}

相关内容