pgfplots:如何在表格图中获取 xtick=data

pgfplots:如何在表格图中获取 xtick=data

在此处输入图片描述

我设置了xtick=data, % no effectxtick={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}]

看起来稍微好一点:

在此处输入图片描述

相关内容