我在 .txt 文件中有下表
Group Real Imag Cable VSC P-mode VSC Vdc-mode
A -1.2739095e+02 -3.3612954e+02 4.9822998e-01 4.9309456e-01 8.6754595e-03
B -3.6562225e+02 -1.5159071e-08 9.9466377e-01 5.3144496e-03 2.1780579e-05
C -1.3022349e+02 -6.4822263e+01 0.0000000e+00 5.0000000e-01 5.0000000e-01
D -2.9475053e+01 -3.6893573e+01 3.1371907e-03 4.9483474e-01 5.0202807e-01
E -1.6348086e+01 2.1641636e-10 0.0000000e+00 1.0000000e+00 0.0000000e+00
F -2.1006393e+02 -2.1418017e+02 1.6515906e-01 3.8119125e-02 7.9672181e-01
G -9.9999998e+02 0.0000000e+00 2.7782889e-03 4.6066919e-01 5.3655252e-01
我正在尝试使用以下代码绘制条形图:
\documentclass[varwidth]{standalone}
% *** PACKAGES ***
\usepackage{standalone} % Pour les stand-alone
\usepackage[usenames,dvipsnames]{xcolor} % 68 dvips colors à déclarer avant tikz
\usepackage{tikz} % Pour les figure Tikz
\usepackage{pgfplots} % Pour tracer les courbes à partir de fichiers de données
\usepackage{pgfplotstable} % Pour pouvoir lire les tableaux des fichiers .txt
% *** PACKAGES END ***
\usepgfplotslibrary{units} % LATEX and plain TEX
\usepgfplotslibrary[units] % ConTEXt
\usetikzlibrary{pgfplots.units} % LATEX and plain TEX
\usetikzlibrary[pgfplots.units] % ConTEXt
\pgfplotsset{compat=1.13} % pour définir la version de pgfplots
% LaTeX_Color_List={'BrickRed' 'Blue' 'ForestGreen' 'BurntOrange' 'DarkOrchid' 'Sepia' 'Aquamarine' 'RubineRed' 'Gray' 'Black'};
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=1\textwidth,
height=0.4\textwidth,
ybar stacked,
bar width=30pt,
enlarge y limits={upper, value=0},
enlarge x limits = 0.1,
symbolic x coords={A,B,C,D,E,F,G},
%xtick={A,B,C,D,E,F,G},
xlabel=Eigenvalues,
ylabel=Participation Ratio,
axis lines*=left,
y axis line style={opacity=0},
cycle list={
{fill=Blue!85,draw=Blue!85},
{fill=Blue!50,draw=Blue!50},
{fill=Blue!20,draw=Blue!20}},
legend style={at={(0.5,-0.4)},
anchor=north,legend columns=-1}
]
\addplot table[skip first n=1, x index=0, y index=3] {./DATA/VSC_EigenValues_Real_Imag_cable_Pf_Conv1Pf_Conv2Pf.txt};
\addplot table[skip first n=1, x index=0, y index=4] {./DATA/VSC_EigenValues_Real_Imag_cable_Pf_Conv1Pf_Conv2Pf.txt};
\addplot table[skip first n=1, x index=0, y index=5] {./DATA/VSC_EigenValues_Real_Imag_cable_Pf_Conv1Pf_Conv2Pf.txt};
\legend{DC Cable~~~~, P-mode VSC~~~~, Vdc-mode VSC}
\end{axis}
\end{tikzpicture}
\end{document}
但是,如您所见,只绘制了 BCDEFG 条,而没有绘制 A 条,我不知道为什么。有人能帮我吗?
更奇怪的是,如果我在 txt 文件和代码中将“A”更改为“1”,它就可以起作用......
答案1
skip first n=1
从命令中删除\addplot table
。如果没有header=false
选项table
,\addplot table
则使用数据文件的第一行作为列名。
代码:
\begin{filecontents*}{a.txt}
Group Real Imag Cable {VSC P-mode} {VSC Vdc-mode}
A -1.2739095e+02 -3.3612954e+02 4.9822998e-01 4.9309456e-01 8.6754595e-03
B -3.6562225e+02 -1.5159071e-08 9.9466377e-01 5.3144496e-03 2.1780579e-05
C -1.3022349e+02 -6.4822263e+01 0.0000000e+00 5.0000000e-01 5.0000000e-01
D -2.9475053e+01 -3.6893573e+01 3.1371907e-03 4.9483474e-01 5.0202807e-01
E -1.6348086e+01 2.1641636e-10 0.0000000e+00 1.0000000e+00 0.0000000e+00
F -2.1006393e+02 -2.1418017e+02 1.6515906e-01 3.8119125e-02 7.9672181e-01
G -9.9999998e+02 0.0000000e+00 2.7782889e-03 4.6066919e-01 5.3655252e-01
\end{filecontents*}
\documentclass[varwidth]{standalone}
% *** PACKAGES ***
\usepackage{standalone} % Pour les stand-alone
\usepackage[usenames,dvipsnames]{xcolor} % 68 dvips colors à déclarer avant tikz
\usepackage{pgfplots} % Pour tracer les courbes à partir de fichiers de données
\usepackage{pgfplotstable} % Pour pouvoir lire les tableaux des fichiers .txt
% *** PACKAGES END ***
\usepgfplotslibrary{units} % LATEX and plain TEX
\usepgfplotslibrary[units] % ConTEXt
\usetikzlibrary{pgfplots.units} % LATEX and plain TEX
\usetikzlibrary[pgfplots.units] % ConTEXt
\pgfplotsset{compat=1.13} % pour définir la version de pgfplots
% LaTeX_Color_List={'BrickRed' 'Blue' 'ForestGreen' 'BurntOrange' 'DarkOrchid' 'Sepia' 'Aquamarine' 'RubineRed' 'Gray' 'Black'};
\begin{document}
\begin{tikzpicture}
\begin{axis}[
width=1\textwidth,
height=0.4\textwidth,
ybar stacked,
bar width=30pt,
enlarge y limits={upper, value=0},
enlarge x limits = 0.1,
symbolic x coords={A,B,C,D,E,F,G},
xlabel=Eigenvalues,
ylabel=Participation Ratio,
axis lines*=left,
y axis line style={opacity=0},
cycle list={
{fill=Blue!85,draw=Blue!85},
{fill=Blue!50,draw=Blue!50},
{fill=Blue!20,draw=Blue!20}},
legend style={at={(0.5,-0.4)},
anchor=north,legend columns=-1}
]
\addplot table[ x index=0, y index=3] {a.txt};
\addplot table[ x index=0, y index=4] {a.txt};
\addplot table[ x index=0, y index=5] {a.txt};
\legend{DC Cable~~~~, P-mode VSC~~~~, Vdc-mode VSC}
\end{axis}
\end{tikzpicture}
\end{document}