
ポイントの x 座標を追加の x ティックとして入力する必要がありますが、ポイントが多数存在し、それらを重複させる可能性があるため、一般的な方法は非合理的ですextra x ticks
。
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\begin{document}
%---------------------------------------------------------
\begin{tikzpicture}[
]
\begin{axis}[
width=\linewidth, axis lines = middle,
extra x ticks = {1.1, 2.2,3.3}, % irrational decision, because there can be many points
xtick=data,
]
\addplot[] {x};
\addplot[color=red,mark=*, only marks] coordinates {
(1.1,1)
(2.2,2)
(3.3,3)
};
\end{axis}
\end{tikzpicture}
%---------------------------------------------------------
\end{document}
答え1
もし、するなら
xtick=data, % data points from first \addplot
extra x ticks={-4,...,4} % regularly spaced ticks
最初の の各点に目盛りが付き\addplot
、さらに等間隔の目盛りが追加されます。ただし、少し乱雑になる可能性があります。それらを分離する方法の1つは、座標目盛りを下に移動することです。つまり、
xticklabel style={yshift=-15pt},
extra x tick style={tick label style={yshift=15pt}}
最初の行は追加の目盛りラベルにも影響するため、2 行目が必要になります。
の場合nodes near coords
、point meta=x,nodes near coords
のオプションを追加すると\addplot
、そのプロットのポイントの横に x 値が追加されます。以下のコードは、これら両方を示しています。
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\begin{document}
%---------------------------------------------------------
\begin{tikzpicture}[
]
\begin{axis}[
width=\linewidth,
axis lines = middle,
xtick=data, % data points from first \addplot
extra x ticks={-4,...,4}, % regularly spaced ticks
xticklabel style={yshift=-15pt},
extra x tick style={tick label style={yshift=15pt}}
]
\addplot[color=red,mark=*,
only marks,
point meta=x, % use x-value for nodes near coords
nodes near coords
] coordinates {
(1.1,1)
(2.2,2)
(3.3,3)
};
\addplot[] {x};
\end{axis}
\end{tikzpicture}
%---------------------------------------------------------
\end{document}