从图表中删除轴标记

从图表中删除轴标记

我有以下图表,但我想删除 x 轴和 y 轴的虚线标记。我该怎么做?有没有办法将 $y$ 轴标签放在线的顶部而不是右侧?

在此处输入图片描述

\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\begin{document}
    \begin{tikzpicture}
    \begin{axis}[
        axis lines=center,
        xmax = 1.1,
        ymax = 1.1,
        ylabel=$y$,
        xlabel=$x$,
        ]
        \addplot [domain=0:1,samples=250, ultra thick, blue] {sqrt(x)}
            node [pos=0.9, above left] {$y=\sqrt{x}$};
        \addplot [domain=0:1,samples=250, ultra thick, red ] {x}
            node [pos=0.3, below right] {$y=x$};
    \end{axis}
    \end{tikzpicture}
\end{document}

答案1

问题 1 我正在尝试删除 x 轴和 y 轴的虚线标记。

您可以使用以下方式全局删除刻度和刻度标签,\pgfplotsset{ticks=none}或者在axis环境中使用xtick=\empty,ytick=\empty,xticklabels=\empty,yticklabels=\empty

第二季度 有什么方法可以将 $y$ 轴标签放在线的顶部而不是右侧?

在这里,你可以使用以下方式定义放置轴标签的节点x label style={at={(axis description cs:1,0)},anchor=west}, y label style={at={(axis description cs:0,1)},anchor=south},

在此处输入图片描述

\documentclass[varwidth=\maxdimen]{standalone}
\usepackage{pgfplots}

%\pgfplotsset{compat=newest, ticks=none}

\begin{document}
    \begin{figure}
        \centering
        \caption{this is caption}
        \label{fig:fig}
        \begin{tikzpicture}
            \begin{axis}[
                axis lines=center,
                xmax = 1.1,
                ymax = 1.1,
                x label style={at={(axis description cs:1,0)},anchor=west},
                y label style={at={(axis description cs:0,1)},anchor=south},
                ylabel=$y$,
                xlabel=$x$,
                xtick=\empty,
                ytick=\empty,
                xticklabels=\empty,
                yticklabels=\empty
                ]
                \addplot [domain=0:1,samples=250, ultra thick, blue] {sqrt(x)}
                node [pos=0.9, above left] {$y=\sqrt{x}$};
                \addplot [domain=0:1,samples=250, ultra thick, red ] {x}
                node [pos=0.3, below right] {$y=x$};
            \end{axis}
        \end{tikzpicture}
    \end{figure}
\end{document}

答案2

我不确定我是否理解正确。您是否在遵循以下规则:

在此处输入图片描述

\documentclass[border=2pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}

\begin{document}
    \begin{tikzpicture}
\begin{axis}[
    axis lines=center,
    ticks= none,  % <--- added
    xmax = 1.1, xlabel=$x$, xlabel style={right}, % <--- added position of xlabel 
    ymax = 1.1, ylabel=$y$, ylabel style={above}, % <--- added position of ylabel 
    domain=0:1, samples=250, % <--- both graph has the same domain and number of samples
    ]
\addplot [ultra thick, blue] {sqrt(x)}
    node [pos=0.9, above left] {$y=\sqrt{x}$};
\addplot [ultra thick, red ] {x}
    node [pos=0.3, below right] {$y=x$};
\end{axis}
    \end{tikzpicture}
\end{document}

相关内容