Algunos problemas con un gráfico de áreas apiladas: pgfplot

Algunos problemas con un gráfico de áreas apiladas: pgfplot

Tengo tres problemas con un gráfico de áreas apiladas.

1: Quiero que la trama sea más ancha para que quepa en mi presentación. Pero si escala en la dirección x, también escala las fuentes (etiquetas). ¿Cómo evitar eso?

ingrese la descripción de la imagen aquí

ingrese la descripción de la imagen aquí

2: Todo lo que intenté para incluir las etiquetas de marca \sffamilyno funcionó. Probablemente no encontré el interruptor correcto. ¿Como podría hacerlo?

3: Me gustaría cambiar el xlabels. La trama debería comenzar con 2014 pero el etiquetado con 2015. Las marcas sin etiqueta deberían tener |. Intento ilustrar lo que quiero para xlabels:

__________________________________________
      |  |   |  |   |  |   |  |   |  |   |
0   2015   2017   2019   2021   2023   2025

Esto es lo que probé hasta ahora:

\documentclass{standalone}              
\usepackage{pgfplots}
\usepgfplotslibrary{dateplot}
\usepackage[ngerman]{babel}

\pgfplotstableread[col sep=comma,header=true]{
    Year,pid,pack,diff
    2014,4.5,4.5,0
    2015,3.1,4,0.9
    2016,4.5,5.8,1.3
    2017,3.1,4.9,1.8
    2018,2.8,5.2,2.4
    2019,2.3,3.9,1.6
    2020,2,3.9,1.9
    2021,2.1,3.9,1.8
    2022,2.1,5.5,3.4
    2023,0,3.95,3.95
    2024,0,4,4
    2025,0,3.95,3.95
}\table

\pgfplotsset{
    /pgfplots/area cycle list/.style={/pgfplots/cycle list={%
        {red,fill=red,mark=none},
        {blue,fill=blue,mark=none},
    }
},
every axis label = {font=\sffamily},
every tick label/.append style={font=\sffamily},
}


\begin{document}

\begin{tikzpicture}[font=\sffamily]
    \begin{axis}[ 
            every axis label={font=\sffamily},
            legend style = {font=\sffamily},
            label style = {font=\sffamily},
            tick style = {font=\sffamily},
            area style, 
            stack plots=y, 
            enlarge x limits=false, 
            enlarge y limits=upper, 
            x tick label style={/pgf/number format/1000 sep=},      
            ylabel=y, y label style={at={(0.05,1)}},%
            xlabel=t, x label style={at={(1,0.0)}},%
        ]
%\pgftransformxscale{1.5}%scales in xdirection but stretches also the font
        \addplot table [x=Year, y=pid, fill=green] {\table} \closedcycle;
    \end{axis} 
\end{tikzpicture}

\end{document}

Respuesta1

  1. La pregunta escómoescalas la trama. Si escala el eje directamente usando los comandos widthy heightel tamaño de fuente no cambiará.
  2. Esta es una pregunta muy común y respondida.aquíPor ejemplo. En resumen, solo cambió la fuente "normal", pero no la fuente "matemática". Y como los ticknúmeros se imprimen en modo matemático, obtienes la fuente matemática predeterminada.
  3. Aquí puede simplemente indicar las etiquetas "a mano" usando la xtickclave y proporcionar los valores que desea mostrar. Como puedes ver en el código, también puedes usar una versión "inteligente". Con la minor x tick numclave puedes proporcionar el número de tick menor.

\documentclass{standalone}
\usepackage[ngerman]{babel}
\usepackage[eulergreek]{sansmath}
\usepackage{pgfplots}
    \usepgfplotslibrary{dateplot}
    \pgfplotstableread[col sep=comma,header=true]{
        Year,pid,pack,diff
        2014,4.5,4.5,0
        2015,3.1,4,0.9
        2016,4.5,5.8,1.3
        2017,3.1,4.9,1.8
        2018,2.8,5.2,2.4
        2019,2.3,3.9,1.6
        2020,2,3.9,1.9
        2021,2.1,3.9,1.8
        2022,2.1,5.5,3.4
        2023,0,3.95,3.95
        2024,0,4,4
        2025,0,3.95,3.95
    }\table
    \pgfplotsset{
        /pgfplots/area cycle list/.style={
            /pgfplots/cycle list={%
                {red,fill=red,mark=none},
                {blue,fill=blue,mark=none},
            },
        },
    }
\begin{document}
\begin{tikzpicture}[
    font=\sffamily\sansmath,
]
    \begin{axis}[
        area style,
        stack plots=y,
        enlarge x limits=false,
        enlarge y limits=upper,
        x tick label style={/pgf/number format/1000 sep=},
        ylabel=y, y label style={at={(0.05,1)}},%
        xlabel=t, x label style={at={(1,0.0)}},%
        % -------------------------------------------------
        % set `xtick's
        xtick={2015,2017,...,2025},
        % show in between major xticks 1 minor tick
        minor x tick num=1,
        % change width of the plot
        width=10cm,
        % and maintain (original) height
        % (or also change me, if needed)
        height=\axisdefaultheight,
%        % if the plot should fill the whole page, try the following key
%        scale mode=stretch to fill,
    ]
%\pgftransformxscale{1.5}%scales in xdirection but stretches also the font
        \addplot table [x=Year, y=pid, fill=green] {\table} \closedcycle;
    \end{axis}
\end{tikzpicture}
\end{document}

imagen que muestra el resultado del código anterior

información relacionada