Mac 上的 TikZ + gnuplot

Mac 上的 TikZ + gnuplot

我在工作中经常使用 LaTeX,最近我改用 Mac。我安装了 TeX Live,除了使用 gnuplot 绘制图形外,其他一切都运行正常。

我首先按照网上的说明在终端中简单地安装了 gnuplot 4.4.3,但没有成功,然后上网后我安装了 Fink 和 Macports,并通过 Macports 再次安装了 gnuplot。我知道这很乱,但错误消息没有改变,一直是一样的,如下所示:

gnuplot> set table "proba.f0.table"; set format "%.5f"
             ^
         "proba.f0.gnuplot", line 1: valid set options:  [] = choose one, {} means optional

    'angles', 'arrow', 'autoscale', 'bars', 'border', 'boxwidth',
    'clabel', 'clip', 'cntrparam', 'colorbox', 'contour', 'decimalsign',
    'dgrid3d', 'dummy', 'encoding', 'fit', 'format', 'grid',
    'hidden3d', 'historysize', 'isosamples', 'key', 'label', 'locale',
    'logscale', '[blrt]margin', 'mapping', 'mouse', 'multiplot',
    'offsets', 'origin', 'output', 'palette', 'parametric', 'pm3d',
    'pointsize', 'polar', 'print', '[rtuv]range', 'samples', 'size',
    'style', 'surface', 'terminal', tics', 'ticscale', 'ticslevel',
    'timestamp', 'timefmt', 'title', 'view', '[xyz]{2}data',
    '[xyz]{2}label', '[xyz]{2}range', '{no}{m}[xyz]{2}tics',
    '[xyz]{2}[md]tics', '{[xyz]{2}}zeroaxis', 'zero'



Package pgf Warning: Plot data file `proba.f0.table' not found. on input line 4
6.

Latex代码如下:

\documentclass[trans]{beamer}

\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{amsmath,amsthm}
\usepackage{pgffor}
\usepackage{tikz}
\usepackage{hyperref}

\newenvironment{stepenumerate}{\begin{enumerate}[<+->]}{\end{enumerate}}
\newenvironment{stepitemize}{\begin{itemize}[<+->]}{\end{itemize} }
\newenvironment{stepenumeratewithalert}{\begin{enumerate}[<+-| alert@+>]}{\end{enumerate}}
\newenvironment{stepitemizewithalert}{\begin{itemize}[<+-| alert@+>]}{\end{itemize} }
\usetheme{CambridgeUS}
%\useoutertheme[footline=authortitle]{miniframes}
%\setbeamercovered{still covered={\opaqueness<1->{25}}} 
\setbeamercovered{invisible}
\usefonttheme{structurebold}

\begin{document}


\begin{frame}
  \frametitle{P.d.f. with different degrees of freedom}

  \begin{center}
  \begin{tikzpicture}[y=5cm]
    \draw[domain=0:4,thick,color=orange] plot[id=f0,samples=100] 
       function{0.5*(gamma(3)/(gamma(1)*gamma(2)))*1/((1+0.5*x)**3)} node at (1,0.8) {$\scriptstyle n=2\textsf{,}\; m=4$};

    \draw (0,0) node[below left] {$0$};
    \draw (3.5,1) node[above] {$\scriptstyle f\left(x;n,m\right)=\left(\frac{n}{m}\right)^{\frac{n}{2}}\frac{\Gamma\left(\frac{n+m}{2}\right)}{\Gamma\left(\frac{n}{2}\right)\Gamma\left(\frac{m}{2}\right)}\frac{x^{\frac{n}{2}-1}}{\left(1+\frac{n}{m}x\right)^{\frac{n+m}{2}}}$};

    \draw[->,semithick] (-0.2,0) -- (4.2,0) node[right] {$x$};
    \draw[->,semithick] (0,-0.05) -- (0,1.2) node[left] {$f\left(x\right)$};

    \foreach \x in {1,2,...,4}
      \draw (\x,2pt) -- (\x,-2pt) node[below] {\x};
    \foreach \y in {0.2,0.4,0.6,0.8,1}
      \draw (2pt,\y) -- (-2pt,\y) node[left] {\y};
  \end{tikzpicture}
  \end{center}

  \transwipe
\end{frame}

\end{document}

问题可能出在哪里?我无法解决它,但我想在 Mac 上使用 gnuplot。


编辑 1(从版主的回答移至此处)

非常感谢您的快速回复。很抱歉,我有几个问题没有说清楚。

  1. 我正在使用 TexShop,它运行良好。
  2. --shell-escape已配置,并且-enable-write18
  3. gnuplot 可以工作,尽管我认为我安装了两次...当我在终端中输入 时gnuplot,它会以补丁级别 3 启动 gnuplot 4.4,但是当我输入 时/usr/local/bin/gnuplot,它会以补丁级别 0 启动 gnuplot 4.0。第一次设置 aquaterm(已安装)并且不绘图,第二次设置 X11(也已安装)运行良好。这可能是问题吗?我应该保留哪一个以及如何卸载另一个?
  4. 放置& -shell-escape在文档的开头会导致出现错误消息:Misplaced alignment tab character &
  5. 由于 gnuplot 不起作用,我现在使用 pgfplot,它也很好,但是 gnuplot 更灵活,我可以用它表示更多功能。
  6. 其他网站上有人建议改变pgfmoduleplot.code.tex文件并更改行

    \xdef\pgf@gnuplot@head#1{set terminal table; set output “#1.table”; set format “%.5f”} 
    

    \xdef\pgf@gnuplot@head#1{set table; set output “#1.table”; set format “%.5f”}
    

    然而,我没有这样的线,但是有

     \xdef\pgf@gnuplot@head{set table \noexpand\pgf@plottablefile@quoted; set format "%.5f"}
    

编辑 2(从版主的回答移至此处)

我想我找到问题所在了。正如我之前所写,我安装了两个 gnuplot。当我在终端中输入 gnuplot 时,它会以补丁级别 3 启动 gnuplot 4.4,但是当我输入 /usr/local/bin/gnuplot 时,它会以补丁级别 0 启动 gnuplot 4.0。

我尝试在终端中创建 gnuplot 表gnuplot proba.f0.gnuplot,它运行良好,然后 TexShop 可以完成工作。但是,当我尝试使用其他版本并写入时,/usr/local/bin/gnuplot proba.f0.gnuplot它给出了熟悉的错误消息。

所以问题肯定出在 4.0 版本上。我怎样才能从 /usr/local/bin 中卸载它并将另一个放在那里?

编辑3

@Altermundus:非常感谢,我能够从 卸载 gnuplot /usr/local/bin。现在我唯一要做的就是让 Texshop 在 中找到 gnuplot /opt/local/bin,因为该版本可以手动运行。我该怎么做?

答案1

  1. 首先你需要测试它是否gnuplot能工作。我编译了源代码,但你也可以使用 fink 或 macport 版本;
  2. 现在您可以gnuplot在终端中测试$ gnuplot
  3. 然后gnuplot必须在 中找到path。一个简单的解决方案是创建一个链接,例如通过/usr/local/bin/真实文件gnuplot,但如果你知道如何做,你可以直接修改你的路径(在终端中测试路径$ echo $PATH:)
  4. 最后,您需要授权在脚本中TeX启动“gnuplot with--shell-escape”进行编译。

我不太喜欢使用 Fink 或 Macport,我更喜欢编译源代码。默认情况下,二进制文件位于 /usr/local/bin 中(我认为是 ..),但很容易更改。下一个方法是只获取与 tikz 一起使用的版本并获取表格。获取包含所有终端(png 等)的版本更复杂。安装 Aquaterm 是个好办法!

  1. 下载源代码请见:gnuplot 源然后将文件夹 gnuplot-4.4.3 放在桌面上
  2. $ cd /Users/.../Desktop/gnuplot-4.4.3
  3. $ ./configure --with-readline=builtin以避免 Leopard 上的 readline 错误问题。
  4. $ make
  5. $ sudo make install
  6. gnuplot 测试$ gnuplot
  7. 尝试使用 TexShop,这是使用 TeX 最简单的方法。

相关内容