如何删除给定图表中的一个“0”(原始标签)?

如何删除给定图表中的一个“0”(原始标签)?

我想知道是否有人能帮我移除原点标签并将“0”精确地放在角落位置。根据我的理解,我们似乎应该移除这些标签并添加

extra x ticks={0},
extra x tick style={xticklabel style={anchor=northeast}},

但是当我这样做时,结果有 3 个原产地标签。 在此处输入图片描述

以下是我正在使用的代码

\documentclass[a4paper,12pt]{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{pgf}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{amsmath}
\usepackage{enumerate}
\usepackage{tikz} % Required for tikz drawing
\usepackage[ngerman]{babel}
\usepackage{biblatex}
\usepackage{comment}
\usepackage{graphicx}

\usepgfplotslibrary{fillbetween}

\usetikzlibrary{arrows}
\usetikzlibrary{patterns}
\usetikzlibrary{arrows}
\usetikzlibrary{decorations.markings}
\usetikzlibrary{positioning}
\usetikzlibrary{shapes.geometric} % <- for regular polygon nodes
\usetikzlibrary{calc}
\usetikzlibrary{shapes.misc}

\usepackage[paperwidth=5in, paperheight=3.6in]{geometry}
\geometry{left=2mm, right=2mm, top=4mm, bottom=2mm}

\pgfplotsset{compat=newest}

\begin{document}
\begin{figure}[!t]
\centering
\begin{tikzpicture}[
        every pin/.style = {pin edge={Latex-,thin,black}},
        small dot/.style={fill=black,circle,scale=0.3}, E/.style={font=\small,text=Orange, sloped, pos=0.75},
        mystyle/.style={draw=red, label={#1}},
        declare function={a(\x)=50*\x;},
        ]
\begin{axis}[
        axis y line=left,
        axis x line=bottom,
        grid=major,
        ylabel = $\textbf{Words typed}$,
        xlabel = $\textbf{Time in minutes}$,
        width=4.7in,height=3.3in,
        ymin=0,ymax=325,
        xmin=0,xmax=8.5,
        %grid style={dashed, line width=.2pt, draw=blue!25},
        %major grid style={line width=.3pt, draw=blue!60},
        %minor tick num=4,
        axis line style = thick,
        major tick style = thick,
        %x minor tick num=4,
        xtick distance = 1,
        %xsubticksize=1,
        %xtick={1,2,3},
        %xtick style={},
        %xtick={-4,-3,-2,-1,1,2,3,4},
        x grid style={thin, opacity=0.5},
        %extra x ticks={0},
        %extra x tick style={xticklabel style={anchor=northeast}},
        ytick distance = 50,
        %ysubticksize=1,
        %ytick={1,2,3},
        %ytick style={small},
        %ytick={0,5000,10000,15000,20000,25000},
        y grid style={thin, opacity=0.5},
        %axis lines = middle,
        %y axis line style = {ultra thick, stealth-stealth},
        %x axis line style = {ultra thick, stealth-stealth},
        %y tick label style={/pgf/number format/.cd, scaled y ticks = false, set thousands separator={,}, set decimal separator={.},fixed, /tikz/.cd},
        %every tick label/.append style={font=\scriptsize},
        %every x tick label/.append style={anchor=north, },
        %every y tick label/.append style={anchor=east, },
        %every axis x label/.style={ at={(current axis.right of origin)}, anchor=west, font=\footnotesize, },
        %every axis y label/.style={ at={(current axis.above origin)},  anchor=south, font=\footnotesize, },
        axis on top=false,
        ]

%FUNCTION
\addplot[name path=a, ultra thick, -latex, samples=300, smooth, domain=0:6.5, red] {a(x)}  node [pos=0.9,left,red,font=\small] {};

\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

答案1

将以下内容添加到 的选项列表中axis

xtick={1,...,8},                                % explicitly sets ticks 1 to 8 for x-axis
ytick={50,100,...,300},                         % explicitly sets ticks 50 to 300 for y-axis
extra x ticks={0},                                           % sets one extra tick at 0
extra x tick style={xticklabel style={anchor=north east}},   % aligns extra tick

最后,你的代码应该是这样的:

\documentclass[12pt]{article}
\usepackage[paperwidth=5in, paperheight=3.6in]{geometry}
\geometry{left=2mm, right=2mm, top=4mm, bottom=2mm}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}

\begin{document}
\begin{figure}[!t]
\centering
\begin{tikzpicture}[
        declare function={a(\x)=50*\x;},
    ]
    \begin{axis}[
        axis y line=left,
        axis x line=bottom,
        grid=major,
        ylabel = $\textbf{Words typed}$,
        xlabel = $\textbf{Time in minutes}$,
        width=4.7in, height=3.3in,
        ymin=0, ymax=325,
        xmin=0, xmax=8.5,
        axis line style = thick,
        major tick style = thick,
        xtick distance = 1,
        x grid style={thin, opacity=0.5},
        ytick distance = 50,
        y grid style={thin, opacity=0.5},
        axis on top=false,
        xtick={1,...,8},
        ytick={50,100,...,300}, 
        extra x ticks={0},
        extra x tick style={xticklabel style={anchor=north east}}
    ]

%FUNCTION
\addplot[name path=a, ultra thick, -latex, samples=300, smooth, domain=0:6.5, red] {a(x)}  node [pos=0.9, left, red, font=\small] {};

\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

在此处输入图片描述

我强烈建议您清理您的代码并删除不需要的包,并且不要加载两次包。

要删除刻度标记,您可以使用:

extra x tick style={xticklabel style={anchor=north east}, major tick length=0pt}

相关内容