![pgfplots:如何在表格图中获取 xtick=data](https://linux22.com/image/466545/pgfplots%EF%BC%9A%E5%A6%82%E4%BD%95%E5%9C%A8%E8%A1%A8%E6%A0%BC%E5%9B%BE%E4%B8%AD%E8%8E%B7%E5%8F%96%20xtick%3Ddata.png)
我设置了xtick=data, % no effect
或
xtick={1,2,3,...,10}, % no effect
但没有从表中获得数据刻度(1,2,3,...)。
我需要做什么?
\begin{filecontents}{PeriodicTableOfElements3a.csv}
Z,Symbol,MeltingPoint
1,H,14.175
2,He,0.955
3,Li,453.85
4,Be,1560.15
5,B,2573.15
6,C,3948.15
7,N,63.29
8,O,50.5
9,F,53.63
10,Ne,24.703
11,Na,371.15
12,Mg,923.15
13,Al,933.4
14,Si,1683.15
15,P,317.25
16,S,388.51
17,Cl,172.31
18,Ar,83.96
19,K,336.5
20,Ca,1112.15
21,Sc,1812.15
22,Ti,1933.15
23,V,2175.15
24,Cr,2130.15
25,Mn,1519.15
26,Fe,1808.15
27,Co,1768.15
28,Ni,1726.15
\end{filecontents}
\documentclass[a4paper]{article}
\usepackage[margin=5mm]{geometry}
\usepackage{longtable}
\setlength{\LTleft}{0pt}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{pgfplotstable}
\pgfplotstableread[col sep=comma]{PeriodicTableOfElements3a.csv}{\mytable}
\pgfplotstableset{
begin table=\begin{longtable},
end table=\end{longtable},
}
\begin{document}
\pgfplotstabletypeset[
columns={Z, Symbol, MeltingPoint},
string type,
skip rows between index={26}{666}
]{\mytable}
\begin{tikzpicture}[font=\footnotesize]
\begin{axis}[]
\addplot[
restrict x to domain=1:25,
% Problem here =============================
xtick=data, % no effect
%xtick={1,2,3,...,10}, % no effect
% ======================================
point meta=explicit symbolic,% Symbol 1/3
nodes near coords,% Symbol 2/3
mark=*, mark size=1.0125pt,
] table[meta=Symbol,% Symbol 3/3
x=Z, y=MeltingPoint
] {\mytable};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您正在将钥匙喂给\addplot
但实际上应该将它们喂给axis
。
\begin{filecontents}{PeriodicTableOfElements3a.csv}
Z,Symbol,MeltingPoint
1,H,14.175
2,He,0.955
3,Li,453.85
4,Be,1560.15
5,B,2573.15
6,C,3948.15
7,N,63.29
8,O,50.5
9,F,53.63
10,Ne,24.703
11,Na,371.15
12,Mg,923.15
13,Al,933.4
14,Si,1683.15
15,P,317.25
16,S,388.51
17,Cl,172.31
18,Ar,83.96
19,K,336.5
20,Ca,1112.15
21,Sc,1812.15
22,Ti,1933.15
23,V,2175.15
24,Cr,2130.15
25,Mn,1519.15
26,Fe,1808.15
27,Co,1768.15
28,Ni,1726.15
\end{filecontents}
\documentclass[a4paper]{article}
\usepackage[margin=5mm]{geometry}
\usepackage{longtable}
\setlength{\LTleft}{0pt}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepackage{pgfplotstable}
\pgfplotstableread[col sep=comma]{PeriodicTableOfElements3a.csv}{\mytable}
\pgfplotstableset{
begin table=\begin{longtable},
end table=\end{longtable},
}
\begin{document}
\pgfplotstabletypeset[
columns={Z, Symbol, MeltingPoint},
string type,
skip rows between index={26}{666}
]{\mytable}
\begin{tikzpicture}[font=\footnotesize]
\begin{axis}[xtick=data]
\addplot[
restrict x to domain=1:25,
% Problem here =============================
%xtick=data, % no effect
%xtick={1,2,3,...,10}, % no effect
% ======================================
point meta=explicit symbolic,% Symbol 1/3
nodes near coords,% Symbol 2/3
mark=*, mark size=1.0125pt,
] table[meta=Symbol,% Symbol 3/3
x=Z, y=MeltingPoint
] {\mytable};
\end{axis}
\end{tikzpicture}
\end{document}
如果你使用
\begin{axis}[xtick={1,2,3,...,10,12,14,...,25}]
看起来稍微好一点: