我想删除垂直直线(在楼梯函数中),仅保留虚线并使水平线变为粗体:
另外,我不知道为什么虚线超过了我给出的 y 轴值以及为什么它们会发生位移。
\begin{figure}
\centering
\begin{tikzpicture}[>=latex]
\begin{axis}[
axis x line=bottom,
axis y line=left,
xlabel={A},
ylabel=B},xmax=8,ymax=8,
xtick={2,6},xticklabels={$bs_1$,$bs_k$},
ytick={2,3,6},yticklabels={$b_1$,$b_2$,$b_k$}
]
\addplot [mark=none,draw=blue]
coordinates {(1,1)(1,2)(2,2)(2,3)(3,3)(3,4)(4,4)(4,5)(5,5)(5,6)(6,6)(6,7)(7,7)};
\end{axis}
\draw [dashed,draw=blue] (1,1) -- (1,0);
\draw [dashed,draw=blue] (2,2) -- (2,0);
\draw [dashed,draw=blue] (3,3) -- (3,0);
\end{tikzpicture}
\caption{A B C}
\end{figure}
编辑:
如何\cdots
在 xticklabels 之间添加内容?
答案1
您需要将\draw
命令放在中axis
,并且有一个情节处理程序可以抑制垂直“跳跃”,因此只需说
\addplot [jump mark left,mark=none,draw=blue,domain=1:7,samples=7,thick]{x+1};
可以\cdots
将 添加为extra x tick
,但您无需绘制。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[>=latex]
\begin{axis}[ymin=1,
axis x line=bottom,
axis y line=left,
xlabel={A},
ylabel=B,xmax=8,ymax=8,
xtick={2,6},xticklabels={$bs_1$,$bs_k$},
ytick={2,3,6},yticklabels={$b_1$,$b_2$,$b_k$},
extra x ticks={4},extra x tick label={$\cdots$},
extra x tick style={tick style={draw=none}}
]
% \addplot [mark=none,draw=red]
% coordinates {(1,1)(1,2)(2,2)(2,3)(3,3)(3,4)(4,4)(4,5)(5,5)(5,6)(6,6)(6,7)(7,7)};
\addplot [jump mark left,mark=none,draw=blue,domain=1:7,samples=7,thick]
{x+1};
\draw [dashed,draw=blue] (1,1) -- (1,0);
\draw [dashed,draw=blue] (2,2) -- (2,0);
\draw [dashed,draw=blue] (3,3) -- (3,0);
\end{axis}
\end{tikzpicture}
\caption{A B C}
\end{figure}
\end{document}
或者ultra thick
。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[>=latex]
\begin{axis}[ymin=1,
axis x line=bottom,
axis y line=left,
xlabel={A},
ylabel=B,xmax=8,ymax=8,
xtick={2,6},xticklabels={$bs_1$,$bs_k$},
ytick={2,3,6},yticklabels={$b_1$,$b_2$,$b_k$},
extra x ticks={4},extra x tick label={$\cdots$},
extra x tick style={tick style={draw=none}}
]
% \addplot [mark=none,draw=red]
% coordinates {(1,1)(1,2)(2,2)(2,3)(3,3)(3,4)(4,4)(4,5)(5,5)(5,6)(6,6)(6,7)(7,7)};
\addplot [jump mark left,mark=none,draw=blue,domain=1:7,samples=7,ultra thick]
{x+1};
\draw [dashed,draw=blue] (1,1) -- (1,0);
\draw [dashed,draw=blue] (2,2) -- (2,0);
\draw [dashed,draw=blue] (3,3) -- (3,0);
\end{axis}
\end{tikzpicture}
\caption{A B C}
\end{figure}
\end{document}
答案2
你为什么不把图画得那么简单呢?
\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw
(1,0)--+(-90:.1) node[below]{$bs_1$}
(3,0) +(-90:.1) node[below]{$\cdots$}
(5,0)--+(-90:.1) node[below]{$bs_k$}
(0,1)--+(180:.1) node[left]{$b_1$}
(0,2)--+(180:.1) node[left]{$b_2$}
(0,5)--+(180:.1) node[left]{$b_k$};
\draw[magenta,dashed] (1,0)--+(90:1) (2,0)--+(90:2);
\foreach \j in {1,...,6}
\draw[magenta,line width=2pt] (\j-1,\j)--+(0:1);
\draw[stealth-stealth] (0,7)|-(7,0);
\end{tikzpicture}
\end{document}