latex绘图填充区域颜色问题

发布于 2024-08-12 22:35:00

如图所示,第一象限填充颜色下边界为绘制的曲线,如何填充?图像如下:pic1.png
代码如下:documentclass[12pt]{article}
usepackage{tikz}
usepackage{amsmath}

begin{document}


\begin{tikzpicture}[samples=1000,scale=1.5,xscale=1, yscale=1]
    
    \draw[thick,->] (-3.5,0) -- (3.5,0) node at(3.35,-0.2) {$x$};
    \draw[thick,->] (0,-2.5) -- (0,2.5) node at(0.2,2.3) {$y$};
    
    \draw[semithick,domain=-1.25:1.25]plot({tan(\x r)},\x);
    \draw[dashed](-3,pi/2)--(3,pi/2)(-3,-pi/2)--(3,-pi/2);
    
    \fill[red!30,opacity=0.3] (0,0)--({tan(\x r)},\x)--(2.8,pi/2) --(0,pi/2) --(0,0)-- cycle;
\end{tikzpicture}

end{document}

查看更多

关注者
0
被浏览
522
2 个回答
Sagittarius Rover
Sagittarius Rover 2024-08-12
我要成为TikZ糕手/(ㄒoㄒ)/~~

可以利用pgfplots的方法实现...建议参考pgfplots文档P104的做法。下面是MWE和效果。
image.png

\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{fillbetween}
\usepackage{amsmath}
\begin{document}
    \begin{tikzpicture}[scale=1.5]
        \begin{axis}[
            axis lines=middle,
            axis on top,
            xtick = \empty,
            ytick = \empty,
            xlabel = {$x$},
            ylabel = {$y$},
            xmin=-2.0, xmax=2.0,
            ymin=-2.5, ymax=2.5,
            samples=1000]
            \addplot[semithick,name path=A] ({x},{rad(atan(x))});
            \path[name path=B] (0,pi/2) -- (1.8,pi/2);
            \draw[dashed](-3,pi/2)--(3,pi/2)(-3,-pi/2)--(3,-pi/2);
            \addplot[red!30,opacity=.3] fill between[of=A and B,soft clip={
                (0,0) rectangle (1.8,2)
            }];
        \end{axis}
    \end{tikzpicture}
    
\end{document}

image.png

鱼香肉丝没有鱼先生
脾气不好,别来惹我!!!

\fill 需要一条封闭路径

\fill[red!30,opacity=0.3] (0,0)-- plot[domain=0:1.25] ({tan(\x r)},\x)--(3, pi/2) -- (0, pi/2) -- cycle;
\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{amsmath}

\begin{document}


\begin{tikzpicture}[samples=1000,scale=1.5,xscale=1, yscale=1]
    
    \draw[thick,->] (-3.5,0) -- (3.5,0) node at(3.35,-0.2) {$x$};
    \draw[thick,->] (0,-2.5) -- (0,2.5) node at(0.2,2.3) {$y$};
    
    \draw[semithick,domain=-1.25:1.25]plot({tan(\x r)},\x);
    \draw[dashed](-3,pi/2)--(3,pi/2) (-3,-pi/2)--(3,-pi/2);
    
    \fill[red!30,opacity=0.3] (0,0)-- plot[domain=0:1.25] ({tan(\x r)},\x)--(3, pi/2) -- (0, pi/2) -- cycle;
\end{tikzpicture}
\end{document}

image.png

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览