Errores Mpgraph en ConTeXt

Errores Mpgraph en ConTeXt

Necesito poner algunos gráficos de barras en un documento ConTeXt. Estoy usando mkiv de TeX Live 2011, bajo Gentoo GNU/Linux. Intenté usar Gnuplot pero encontré que mpgraphse adapta mejor a mis necesidades.

Estoy usando este archivo 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

y este archivo de datos

1 4
2 2
3 1
4 2
5 4

como un ejemplo mínimo de "funcionamiento".

Sin embargo, está sucediendo algo extraño: no puedo usar ningún operador del sarithmódulo (usado en mpgraphel módulo para dibujar cuadros). Obtuveesta salidacon Contexto. Intenté compilar con Metapost, aunque no obtuve errores ni advertencias, el archivo .dvi de salida está dañado.

También lo intenté con TeX Live 2012 en Windows 7. No puedo compilar allí debido a ese sarithproblema, pero cuando comento esas líneas, funciona. Pero hacer lo mismo en mi cuadro Gentoo funciona, excepto que el texto para las etiquetas o el eje no aparece, solo un pequeño cuadrado. No entiendo lo que está pasando, ni siquiera el ejemplo de la wiki de ConTeXt funciona. ¿Pistas? ¡Se agradece mucho cualquier ayuda!

Respuesta1

Necesitas reemplazar \usepackage[sarith]con

\startMPinitializations
input sarith;
\stopMPinitializations

sarithno es un módulo ConTeXt, sino un paquete metapost, por lo que debe incluirse al final del metapost.

Además, como señaló morbusg, no es necesario agregar beginfig(1)...endfigun MPcodeentorno. Con estos dos cambios, funciona lo siguiente:

\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

Respuesta2

Para cambiar la fuente de los números en las cuadrículas, descubrí que si configuro manualmente los valores de la cuadrícula, en lugar de usar la configuración automática, la fuente se convierte al formato del documento. Aquí hay un ejemplo de la documentación MPGraph de John Handy con mi revisión:

Original

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;

con

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;

Probar esto.

información relacionada