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ボックスを描画するためにモジュールで使用)。この出力ConTeXt を使用。Metapost でコンパイルしてみましたが、エラーや警告は出ませんでしたが、出力 .dvi が破損しています。

Windows 7 の TeX Live 2012 でも試してみました。このsarith問題のためコンパイルできませんが、その行をコメントすると動作します。しかし、同じことを Gentoo ボックスで実行すると動作しますが、ラベルや軸のテキストが表示されず、非常に小さな四角形だけが表示されます。何が起こっているのかわかりません。ConTeXt wiki の例も動作しません。ヒントはありますか? どのような助けでも大歓迎です!

答え1

置き換える必要があり\usepackage[sarith]ます

\startMPinitializations
input sarith;
\stopMPinitializations

sarithは ConTeXt モジュールではなく、metapost パッケージなので、metapost の最後に含める必要があります。

beginfig(1)...endfigさらに、morbusg が指摘したように、環境を追加する必要はありませんMPcode。これら 2 つの変更により、次のようになります。

\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;

これを試してみてください。

関連情報