ConTeXt 中的 Mpgraph 錯誤

ConTeXt 中的 Mpgraph 錯誤

我需要在 ConTeXt 文檔中放入一些條形圖。我在 Gentoo GNU/Linux 下使用 TeX Live 2011 中的 mkiv。我嘗試使用 Gnuplot,但發現mpgraph更適合我的需求。

我正在使用這個 TeX 文件

\usemodule[graph]
\usemodule[sarith]

\enableregime[utf-8]
\starttext

\startMPcode
beginfig(1)
  draw begingraph(12cm,6cm);
    glabel.lft(btex Eje Y etex, OUT);
    glabel.bot(btex Eje X etex, OUT);
    gdata("data.d",
        $,
        path p;
        augment.p (0,$1);
        augment.p ($2,$1);
        augment p ($2,$1 Sadd "1");
        augment p (0,$1 Sadd "1");
        gdraw p withpen pencircle scaled 2bp withcolor red;
    );
  autogrid(grid.bot,grid.lft) withcolor .85white;
  endgraph;
endfig;
\stopMPcode
\stoptext

和這個數據文件

1 4
2 2
3 1
4 2
5 4

作為一個最小的“工作”示例。

然而,發生了一些奇怪的事情:我無法使用sarith模組中的任何運算符(在mpgraph模組中用於繪製框)。我有這個輸出與上下文。我嘗試使用 Metapost 進行編譯,儘管沒有收到錯誤或警告,但輸出 .dvi 已損壞。

我也嘗試過在 Windows 7 下使用 TeX Live 2012 sarith。但是在我的 Gentoo 盒子中做同樣的事情是有效的,除了標籤或軸的文字沒有出現,只是一個很小的方塊。我不明白發生了什麼,甚至 ConTeXt wiki 中的範例也不起作用。線索?非常感謝任何幫助!

答案1

你需要替換\usepackage[sarith]

\startMPinitializations
input sarith;
\stopMPinitializations

sarith不是ConTeXt模組,而是一個metapost包,所以需要包含在metapost端。

而且,正如morbusg指出的那樣,不需要添加beginfig(1)...endfig環境MPcode。透過這兩項更改,可以實現以下效果:

\usemodule[graph]
\startMPinitializations
input sarith;
\stopMPinitializations

\starttext

\startMPcode
  draw begingraph(12cm,6cm);
    glabel.lft(btex Eje Y etex, OUT);
    glabel.bot(btex Eje X etex, OUT);
    gdata("data.d",
        $,
        path p;
        augment.p (0,$1);
        augment.p ($2,$1);
        augment p ($2,$1 Sadd "1");
        augment p (0,$1 Sadd "1");
        gdraw p withpen pencircle scaled 2bp withcolor red;
    );
  autogrid(grid.bot,grid.lft) withcolor .85white;
  endgraph;
\stopMPcode
\stoptext

答案2

為了更改網格上數字的字體,我發現如果我手動設定網格值,而不是使用自動設置,字體將轉換為文件格式。以下是 John Handy 的 MPGraph 文件中的一個範例以及我的修訂版:

原來的

draw begingraph(6.5cm,4.5cm);
    setrange(80,0, 90,whatever);
        glabel.bot(btex Year etex, OUT);
        glabel.lft(btex \vbox{\hbox{Emissions in} \hbox{thousands of}
            \hbox{metric tons} \hbox{(heavy line)}}etex, OUT);
        gdraw "lead.d" withpen pencircle scaled 1.5pt;
        autogrid(,otick.lft);
        setcoords(linear,linear);
    setrange(80,0, 90,whatever);
        glabel.rt(btex \vbox{\hbox{Micrograms} \hbox{per cubic}
            \hbox{meter of air} \hbox{(thin line)}}etex, OUT);
    gdraw "lead.d";
        autogrid(otick.bot,otick.rt);
endgraph;

draw begingraph(6.5cm,4.5cm);
    setrange(79.5,0, 90.5,80) ;
    glabel.bot(btex Year etex, OUT) shifted(-8pt,-2pt);
    glabel.lft(btex \vbox{% -- \hss fills space horizontally; \strut fixes line space
        \hbox to 5cm {\hss \strut Emissions in thousands of \hss}
        \hbox to 5cm {\hss \strut metric tons (solid line) \hss}
    }
    etex, OUT) shifted(83pt,17pt) rotated 90;
    gdraw "lead.d" withpen pencircle scaled 1pt;
    itick.lft(format("\%2",0),0) withcolor white;
    itick.lft(format("\%2",20),20) withcolor white;
    itick.lft(format("\%2",40),40) withcolor white;
    itick.lft(format("\%2",60),60) withcolor white;
    itick.lft(format("\%2",80),80) withcolor white;
    frame.lft withcolor white ;

    otick.bot(format("\%2",80),80) withcolor white;
    otick.bot(format("\%2",82),82) withcolor white;
    otick.bot(format("\%2",84),84) withcolor white;
    otick.bot(format("\%2",86),86) withcolor white;
    otick.bot(format("\%2",88),88) withcolor white;
    otick.bot(format("\%2",90),90) withcolor white;
endgraph;

試試這個。

相關內容