如何在图表中插入千位分隔符

如何在图表中插入千位分隔符

我正在尝试为使用以下代码生成的图表插入千位分隔符逗号。请注意,尽管我将标签设置为每网格 5000,但实际的垂直比例为每网格 50。

我希望 y 标签为 5,000、10,000 等等。

电流输出

先感谢您

\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\renewcommand{\thesection}{\arabic{section}}
\usepackage{mathtools}
\usepackage{cancel}
\usepackage{pgfplots}
\usepackage{amsmath}
\newtheorem{theorem}{THEOREM}
\newtheorem{proof}{PROOF}
\usepackage{tikz}
\usepackage{amssymb}
\usetikzlibrary{patterns}
\usepackage{fancyhdr}
\usepackage{bigints}
\usepackage{color}
\usepackage{tcolorbox}
\usepackage{color,xcolor}
\usepackage{booktabs,array}
\usepackage{hyperref}
\usepackage{graphicx}
\usetikzlibrary{arrows}
\usepackage{polynom}
\usepackage{wallpaper}
\usetikzlibrary{shapes.geometric}
\usepgfplotslibrary{fillbetween}
\newenvironment{tightcenter}{
\setlength\topsep{0pt}
\setlength\parskip{0pt}
\begin{center}}{\end{center}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
axis line style=thick,
axis line style={->},
grid=major,
%grid=both,
%
grid style={line width=.1pt, draw=gray!80},
major grid style={line width=.2pt,draw=gray!80},
%
xmin=0,
xmax=10.3,
ymin=0,
ymax=210,
%
height=15cm,
width=13cm,
%
every tick label/.append style={font=\large},
%
ylabel={\large Y},
xlabel={\large X},
xtick={0,1,2,3,4,5,6,7,8,9,10},
ytick={0,50,100,150,200,250,300,350,400},
yticklabels={0,5000,10000,15000,20000},
%
xlabel near ticks,
ylabel near ticks,
%
ylabel style={rotate=-90},
every x tick/.style={black},
every y tick/.style={black},
clip=false,
%
ylabel style={
%   anchor=south,
%   at={(ticklabel* cs:1.0)},
xshift=-0.2cm
},
xlabel style={
%   anchor=west,
%   at={(ticklabel* cs:1.0)},
yshift=-0.2cm
}
]
\node[left] at (0,0) {\large $0$};
\node[below] at (0,0) {\large $0$};
%
%\draw[thick,color=black,samples=100](axis cs:0,250) -- (axis cs:30,100);
%\draw[thick,color=black,samples=100](axis cs:30,100) -- (axis cs:38,0);
%
\addplot[thick,color=black,samples=100,domain=0:5.5] {9430*1.15^(x)/100};
%\node[right] at (axis cs:17.5,35) {\text{Second machine}};
%\node[right] at (axis cs:20.5,160) {\text{First machine}};
\end{axis}
\newline
\end{tikzpicture}
\end{document}

答案1

yticklabels={0,{5,000},{10,000},{15,000},{20,000}}

由于单个标签包含逗号,因此需要将每个标签括在 中{ }

\documentclass[]{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
axis line style=thick,
axis line style={->},
grid=major,
%grid=both,
%
grid style={line width=.1pt, draw=gray!80},
major grid style={line width=.2pt,draw=gray!80},
%
xmin=0,
xmax=10.3,
ymin=0,
ymax=210,
%
height=15cm,
width=13cm,
%
every tick label/.append style={font=\large},
%
ylabel={\large Y},
xlabel={\large X},
xtick={0,1,2,3,4,5,6,7,8,9,10},
ytick={0,50,100,150,200,250,300,350,400},
yticklabels={0,{5,000},{10,000},{15,000},{20,000}},
%
xlabel near ticks,
ylabel near ticks,
%
ylabel style={rotate=-90},
every x tick/.style={black},
every y tick/.style={black},
clip=false,
%
ylabel style={
%   anchor=south,
%   at={(ticklabel* cs:1.0)},
xshift=-0.2cm
},
xlabel style={
%   anchor=west,
%   at={(ticklabel* cs:1.0)},
yshift=-0.2cm
}
]
\node[left] at (0,0) {\large $0$};
\node[below] at (0,0) {\large $0$};
%
%\draw[thick,color=black,samples=100](axis cs:0,250) -- (axis cs:30,100);
%\draw[thick,color=black,samples=100](axis cs:30,100) -- (axis cs:38,0);
%
\addplot[thick,color=black,samples=100,domain=0:5.5] {9430*1.15^(x)/100};
%\node[right] at (axis cs:17.5,35) {\text{Second machine}};
%\node[right] at (axis cs:20.5,160) {\text{First machine}};
\end{axis}
\newline
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

使用千位分隔符是默认行为。因此,当您对代码进行微小更改时,您会得到想要的结果。请注意,我从您的代码中删除了很多不必要的内容。

% used PGFPlots v1.17
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{compat=1.3}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        % use the starred version so the axis labels are still centered at
        % the axis. Use `left` when you want to start the axis at zero.
        axis lines*=left,
        xmin=0,
        xmax=10.3,
        ymin=0,
        % multiplied by 100
        ymax=21000,
        % use these `tick distance` when you want evenly spaced numbers
        xtick distance=1,
        ytick distance=5000,
        scaled ticks=false,
        % (so you don't need that many `samples`
        smooth,
        samples=25,
        domain=0:5.5,
    ]
        % removed division by 100
        \addplot [thick] {9430*1.15^(x)};
    \end{axis}
\end{tikzpicture}
\end{document}

该图显示了上述代码的结果

相关内容