我是 TEX 新手
我怎样绘制此变量并将四分之一保留在 x 轴上?
date variable
1993Q1 0.71957432
1993Q2 0.622643199
1993Q3 0.557352546
1993Q4 0.78844216
1994Q1 0.677342246
1994Q2 0.752843835
1994Q3 0.823435891
1994Q4 0.869172377
1995Q1 0.822971248
1995Q2 0.759768686
1995Q3 0.662193784
1995Q4 0.744474674
1996Q1 0.665910923
1996Q2 0.776898876
1996Q3 0.923927404
1996Q4 0.840678042
1997Q1 0.735450535
1997Q2 0.850306776
答案1
ybar
这可以通过plot 或sharp
plot来实现,它用于\pgfplotstableread
将数据读入表格,然后绘制表格
代码
\documentclass{article}%[border=1cm]{standalone}
\usepackage{pgfplots,pgfplotstable}
\pgfplotsset{compat=1.8}
\begin{document}
\pgfplotstableread[col sep=comma]{
date, variable
1993Q1, 0.71957432
1993Q2, 0.622643199
1993Q3, 0.557352546
1993Q4, 0.78844216
1994Q1, 0.677342246
1994Q2, 0.752843835
1994Q3, 0.823435891
1994Q4, 0.869172377
1995Q1, 0.822971248
1995Q2, 0.759768686
1995Q3, 0.662193784
1995Q4, 0.744474674
1996Q1, 0.665910923
1996Q2, 0.776898876
1996Q3, 0.923927404
1996Q4, 0.840678042
1997Q1, 0.735450535
1997Q2, 0.850306776
}\datatable
% ybar plot
\begin{tikzpicture}
\begin{axis}[
ybar,
height=10cm,
width=13cm,
enlarge y limits=false,
ymin=0,
ymax=1,
xtick=data,
xticklabels from table={\datatable}{date},
x tick label style={rotate=90, anchor=east}
]
\addplot [fill=blue] table [x expr=\coordindex, y=variable] {\datatable};
\end{axis}
\end{tikzpicture}%
% -- sharp plot
\begin{tikzpicture}
\begin{axis}[
height=10cm,
width=13cm,
enlarge y limits=false,
ymin=0,
ymax=1,
xtick=data,
xticklabels from table={\datatable}{date},
x tick label style={rotate=90, anchor=east}
]
%\addplot [fill=blue] table [x expr=\coordindex, y=variable] {\datatable};
\addplot [sharp plot] table [x expr=\coordindex, y=variable] {\datatable};
\end{axis}
\end{tikzpicture}%
\end{document}