我想知道是否可以直接从 SQL 检索数据以生成 *.dat 文件并使用 pgfplots 绘制图表,例如:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.5}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
title=Inv. cum. normal,
xlabel={$x$},
ylabel={$y$},
]
\addplot[blue] table {*.dat} -> data retrieve directly from SQL database;
\end{axis}
\end{tikzpicture}
\end{document}
答案1
我成功地完成了以下工作,这是一个很棒的集成工具!:
\documentclass{article}
\usepackage{bashful}
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot,statistics}
\pgfplotsset{compat=1.8}
\usepackage{pgfplotstable}
\begin{filecontents}{soyprice.dat}
Date Settle
2016-08-02 985.25
2016-08-03 990.5
2016-08-04 990.5
2016-08-05 1003.75
2016-08-08 1018.75
2016-08-09 1022
2016-08-10 1017
2016-08-11 1022.25
2016-08-12 1003.25
2016-08-15 1023.75
2016-08-16 1019.5
2016-08-17 1030.5
2016-08-18 1032.25
2016-08-19 1027
2016-08-22 1035.25
2016-08-23 1034.25
2016-08-24 1030.75
2016-08-25 998.25
2016-08-26 990.75
2016-08-29 983.25
2016-08-30 965.5
2016-08-31 960
2016-09-01 959
2016-09-02 968.5
\end{filecontents}
\begin{document}
\bash[stdout]
/Applications/MAMP/Library/bin/mysql (YOUR PATH TO MYSQL) -u YOURUSERNAME -pYOURPASSWORD -e "SELECT * FROM YOURDATABASE" > soyprice.dat
\END
\begin{tikzpicture}[scale=1]
\begin{axis}[
xlabel=Date, ylabel=Settle,table/col sep=space|tab|,
date coordinates in=x,
date ZERO=2016-08-01,
xticklabel style={rotate=90},
enlarge x limits = false,
xticklabel={\month-\day},
ymin=900,
ymax=1100,
minor y tick num=25,
xmin=2016-08-02,
xmax=2016-09-02
title={Preço da soja - CME},
]
\addplot[blue] table [x={Date},y={Settle}] {soyprice.dat};
\end{axis}
\end{tikzpicture}
\end{document}