pgfplot Balkendiagrammlegende und Y-Beschriftung

pgfplot Balkendiagrammlegende und Y-Beschriftung

Ich möchte fragen, wie ich an meine Ergebnisse komme.

Mein Code:

\begin{tikzpicture}
    \begin{axis}[ybar stacked,
legend style={cells={anchor=west},at={(1.75,0.89)}}, area legend,
    %legend style={at={(1,-1)}, anchor=north,legend columns=-1,legend cell align=left},
        x tick label style={ /pgf/number format/1000 sep=},
    ylabel=Revenue (\$\,billions),
    enlargelimits=0.05,width=10cm,height=12cm,
    bar width=12pt,
]
    \addplot coordinates
        {(2012,1388) (2013,1388) (2014,1388) (2015,1388) (2016,1388) (2017,1388) (2018,1500)};
        \addlegendentry{\textsc{InkJet Head}} 

    \addplot coordinates
        {(  2012    ,   2995    ) ( 2013    ,   3144.75 ) ( 2014    ,   3294.5  ) ( 2015    ,   2126.45 ) ( 2016    ,   3594    ) ( 2017    ,   3893.5  ) ( 2018    ,   4342.75 ) }; 
        \addlegendentry{\textsc{Pressure sensors}} 

    \addplot  coordinates
        {(  2012    ,   3594    ) ( 2013    ,   3923.45 ) ( 2014    ,   4193    ) ( 2015    ,   4432.6  ) ( 2016    ,   4792    ) ( 2017    ,   5091.5  ) ( 2018    ,   5450.9  ) };
        \addlegendentry{\textsc{Microphones}} 

    \addplot [color=yellow, fill=yellow] coordinates
        {(  2012    ,   5361.05 ) ( 2013    ,   5450.9  ) ( 2014    ,   5690.5  ) ( 2015    ,   5960.05 ) ( 2016    ,   6289.5  ) ( 2017    ,   6529.1  ) ( 2018    ,   6738.75 )};     
        \addlegendentry{\textsc{Accelerometers}} 

    \addplot [color=black, fill=white] coordinates
        {(  2012    ,   6648.9  ) ( 2013    ,   6888.5  )  (    2014    ,   7128.1  ) ( 2015    ,   7188    ) ( 2016    ,   7457.55 ) ( 2017    ,   7637.25 ) ( 2018    ,   7787    )};     
        \addlegendentry{\textsc{Gyroscopes}} 

    \addplot [color=violet, fill=violet] coordinates
        {(  2012    ,   6948.4  ) ( 2013    ,   7337.75 )  (    2014    ,   7547.4  ) ( 2015    ,   7727.1  ) ( 2016    ,   7787    )  (    2017    ,   8086.5  ) ( 2018    ,   8236.25 )};     
        \addlegendentry{\textsc{Digital compass}} 

    \addplot [color=gray, fill=gray] coordinates
        {(  2012    ,   7337.75 ) ( 2013    ,   7906.8  ) ( 2014    ,   8445.9  )  (    2015    ,   9164.7  ) ( 2016    ,   9584) ( 2017    ,   10033.25    ) ( 2018    ,   10482.5 ) };        
        \addlegendentry{\textsc{Inertial combos}} 

    \addplot [color=purple, fill=purple] coordinates
        {(2012,7487.5) (2013,8176.35) (2014,8835.25) (2015,9494.15) (2016,10033.25) (2017,10632.25) (2018,11021.6)};        
        \addlegendentry{\textsc{Microbolometers}} 


\addplot [color=pink, fill=pink] coordinates
        {(  2012    ,   7547.4  ) ( 2013    ,   8236.25 ) ( 2014    ,   8850.225    ) ( 2015    ,   9509.125    ) ( 2016    ,   10048.225   ) ( 2017    ,   10647.225   ) ( 2018    ,   11081.5 ) };
        \addlegendentry{\textsc{PIR \& thermopiles}} 


\addplot [color=olive, fill=olive] coordinates
        {(  2012    ,   7562.375    ) ( 2013    ,   8251.225    ) ( 2014    ,   8865.2  ) ( 2015    ,   9524.1  ) ( 2016    ,   10063.2 ) ( 2017    ,   10662.2 ) ( 2018    ,   11096.475   ) };
        \addlegendentry{\textsc{Micro displays}} 


\addplot [color=magenta, fill=magenta] coordinates
        {(  2012    ,   8386    ) ( 2013    ,   9134.75 ) ( 2014    ,   10033.25    ) ( 2015    ,   10886.825   ) ( 2016    ,   11740.4 ) ( 2017    ,   12608.95    ) ( 2018    ,   13477.5 ) };
        \addlegendentry{\textsc{Projection systems}}


\addplot [color=lime, fill=lime] coordinates
        {(  2012    ,   8685.5  ) ( 2013    ,   9434.25 ) ( 2014    ,   10332.75    )  (    2015    ,   11081.5 ) ( 2016    ,   12129.75    ) ( 2017    ,   12938.4 ) ( 2018    ,   13926.75    ) };
        \addlegendentry{\textsc{Other optical MEMS}}


\addplot [color=green, fill=green] coordinates
        {(  2012    ,   8985    ) ( 2013    ,   10003.3 ) ( 2014    ,   10931.75    ) ( 2015    ,   12219.6 ) ( 2016    ,   13417.6 ) ( 2017    ,   14825.25    ) ( 2018    ,   16472.5 ) };
    \addlegendentry{\textsc{Microfluidics for research}} 


\addplot [color=cyan, fill=cyan] coordinates
        {(  2012    ,   9823.6  ) ( 2013    ,   10931.75    ) ( 2014    ,   12129.75    ) ( 2015    ,   13537.4 ) ( 2016    ,   15124.75    ) ( 2017    ,   16831.9 ) ( 2018    ,   19018.25    ) };
        \addlegendentry{\textsc{Microfluidics for IVD}}


\addplot [color=brown, fill=brown] coordinates
        {(  2012    ,   10123.1 ) ( 2013    ,   11231.25    ) ( 2014    ,   12579   ) ( 2015    ,   14076.5 ) ( 2016    ,   15723.75    )  (    2017    ,   17520.75    ) ( 2018    ,   18419.25    ) };
        \addlegendentry{\textsc{Microdispensers}}


\addplot [color=red, fill=red] coordinates
        {(  2012    ,   10482.5 ) ( 2013    ,   11830.25    ) ( 2014    ,   13327.75    ) ( 2015    ,   14825.25    ) ( 2016    ,   16622.25    ) ( 2017    ,   18628.9 ) ( 2018    ,   21114.75    ) };
        \addlegendentry{\textsc{RF MEMS}}


\addplot [color=orange, fill=orange] coordinates
        {(  2012    ,   10542.4 ) ( 2013    ,   11860.2 ) ( 2014    ,   13447.55    ) ( 2015    ,   14975   ) ( 2016    ,   16921.75    ) ( 2017    ,   19018.25    ) ( 2018    ,   21564   ) };
        \addlegendentry{\textsc{Oscillators}}   


\addplot [color=black, fill=black] coordinates
        {(  2012    ,   10871.85    )  (    2013    ,   12279.5 ) ( 2014    ,   13777   ) ( 2015    ,   17071.5 ) ( 2016    ,   17371   ) ( 2017    ,   19617.25    ) ( 2018    ,   22312.75    ) };
        \addlegendentry{\textsc{Others}}

%\legend{InkJet Head, Pressure sensors, Microphones,  Accelerometers, Gyroscopes, Digital compass, Inertial combos, Microbolometers, PIR \& thermopiles, Micro displays, Projection systems, Other optical MEMS, Microfluidics for research, Microfluidics for IVD, Microdispensers, RF MEMS, Oscillators, Others}
    \end{axis}

Ich habe das: Bildbeschreibung hier eingeben

Ich will das: Bildbeschreibung hier eingeben

Ich habe eine Beschreibung in der Legende in einer Zeile, möchte aber eine Legende unter dem Diagramm mit mehreren Beschreibungen in einer Zeile.

Vielen Dank im Voraus.

Antwort1

Ich bin mir bewusst, dass das nicht genau das ist, was Sie wollten, aber meiner Meinung nach ist das viel klarer, daher rate ich Ihnen, darüber nachzudenken. Wenn Sie auf der unregelmäßigen Variante bestehen, kann Ihnen vielleicht jemand anderes helfen, ich bin mir nicht sicher, ob das möglich ist. Ich denke, Sie müssten auf die Verwendung der pgfplots verzichten \legendund Ihre neue Umgebung definieren.

Bearbeiten: Sie können die YTick-Beschriftungen so einstellen, dass 220000 statt 2,2*10^5 angezeigt werden, indem Sie diesen Code in die Achsenoptionen aufnehmen (nicht im endgültigen Quellcode enthalten).

y tick label style={/pgf/number format/.cd,%
        scaled y ticks = false,
        set thousands separator={\,},
        fixed},

In einer Standardkonfiguration überlappt das Y-Label diese Zahlen. In neueren Versionen von pgfplots ist dies jedoch gelöst. Fügen Sie also z. B.

\pgfplotsset{compat=1.13}

in Ihrer Präambel.

Endgültiger Code:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}

\begin{document}
    \begin{tikzpicture}

    \begin{axis}[ybar stacked,
    legend style={                    % this is modified
        legend cell align=left,       %
        legend columns=2,             %
        at={(xticklabel cs:0.5)},     %
        anchor=north                  % up to here
    }, area legend,
    x tick label style={ /pgf/number format/1000 sep=},
    ylabel=Revenue (\$\,billions),
    enlargelimits=0.05,width=10cm,height=12cm,
    bar width=12pt,
    ]
    \addplot coordinates
    {(2012,1388) (2013,1388) (2014,1388) (2015,1388) (2016,1388) (2017,1388) (2018,1500)};
    \addlegendentry{\textsc{InkJet Head}} 

    \addplot coordinates
    {(  2012    ,   2995    ) ( 2013    ,   3144.75 ) ( 2014    ,   3294.5  ) ( 2015    ,   2126.45 ) ( 2016    ,   3594    ) ( 2017    ,   3893.5  ) ( 2018    ,   4342.75 ) }; 
    \addlegendentry{\textsc{Pressure sensors}} 

    \addplot  coordinates
    {(  2012    ,   3594    ) ( 2013    ,   3923.45 ) ( 2014    ,   4193    ) ( 2015    ,   4432.6  ) ( 2016    ,   4792    ) ( 2017    ,   5091.5  ) ( 2018    ,   5450.9  ) };
    \addlegendentry{\textsc{Microphones}} 

    \addplot [color=yellow, fill=yellow] coordinates
    {(  2012    ,   5361.05 ) ( 2013    ,   5450.9  ) ( 2014    ,   5690.5  ) ( 2015    ,   5960.05 ) ( 2016    ,   6289.5  ) ( 2017    ,   6529.1  ) ( 2018    ,   6738.75 )};     
    \addlegendentry{\textsc{Accelerometers}} 

    \addplot [color=black, fill=white] coordinates
    {(  2012    ,   6648.9  ) ( 2013    ,   6888.5  )  (    2014    ,   7128.1  ) ( 2015    ,   7188    ) ( 2016    ,   7457.55 ) ( 2017    ,   7637.25 ) ( 2018    ,   7787    )};     
    \addlegendentry{\textsc{Gyroscopes}} 

    \addplot [color=violet, fill=violet] coordinates
    {(  2012    ,   6948.4  ) ( 2013    ,   7337.75 )  (    2014    ,   7547.4  ) ( 2015    ,   7727.1  ) ( 2016    ,   7787    )  (    2017    ,   8086.5  ) ( 2018    ,   8236.25 )};     
    \addlegendentry{\textsc{Digital compass}} 

    \addplot [color=gray, fill=gray] coordinates
    {(  2012    ,   7337.75 ) ( 2013    ,   7906.8  ) ( 2014    ,   8445.9  )  (    2015    ,   9164.7  ) ( 2016    ,   9584) ( 2017    ,   10033.25    ) ( 2018    ,   10482.5 ) };        
    \addlegendentry{\textsc{Inertial combos}} 

    \addplot [color=purple, fill=purple] coordinates
    {(2012,7487.5) (2013,8176.35) (2014,8835.25) (2015,9494.15) (2016,10033.25) (2017,10632.25) (2018,11021.6)};        
    \addlegendentry{\textsc{Microbolometers}} 


    \addplot [color=pink, fill=pink] coordinates
    {(  2012    ,   7547.4  ) ( 2013    ,   8236.25 ) ( 2014    ,   8850.225    ) ( 2015    ,   9509.125    ) ( 2016    ,   10048.225   ) ( 2017    ,   10647.225   ) ( 2018    ,   11081.5 ) };
    \addlegendentry{\textsc{PIR \& thermopiles}} 


    \addplot [color=olive, fill=olive] coordinates
    {(  2012    ,   7562.375    ) ( 2013    ,   8251.225    ) ( 2014    ,   8865.2  ) ( 2015    ,   9524.1  ) ( 2016    ,   10063.2 ) ( 2017    ,   10662.2 ) ( 2018    ,   11096.475   ) };
    \addlegendentry{\textsc{Micro displays}} 


    \addplot [color=magenta, fill=magenta] coordinates
    {(  2012    ,   8386    ) ( 2013    ,   9134.75 ) ( 2014    ,   10033.25    ) ( 2015    ,   10886.825   ) ( 2016    ,   11740.4 ) ( 2017    ,   12608.95    ) ( 2018    ,   13477.5 ) };
    \addlegendentry{\textsc{Projection systems}}


    \addplot [color=lime, fill=lime] coordinates
    {(  2012    ,   8685.5  ) ( 2013    ,   9434.25 ) ( 2014    ,   10332.75    )  (    2015    ,   11081.5 ) ( 2016    ,   12129.75    ) ( 2017    ,   12938.4 ) ( 2018    ,   13926.75    ) };
    \addlegendentry{\textsc{Other optical MEMS}}


    \addplot [color=green, fill=green] coordinates
    {(  2012    ,   8985    ) ( 2013    ,   10003.3 ) ( 2014    ,   10931.75    ) ( 2015    ,   12219.6 ) ( 2016    ,   13417.6 ) ( 2017    ,   14825.25    ) ( 2018    ,   16472.5 ) };
    \addlegendentry{\textsc{Microfluidics for research}} 


    \addplot [color=cyan, fill=cyan] coordinates
    {(  2012    ,   9823.6  ) ( 2013    ,   10931.75    ) ( 2014    ,   12129.75    ) ( 2015    ,   13537.4 ) ( 2016    ,   15124.75    ) ( 2017    ,   16831.9 ) ( 2018    ,   19018.25    ) };
    \addlegendentry{\textsc{Microfluidics for IVD}}


    \addplot [color=brown, fill=brown] coordinates
    {(  2012    ,   10123.1 ) ( 2013    ,   11231.25    ) ( 2014    ,   12579   ) ( 2015    ,   14076.5 ) ( 2016    ,   15723.75    )  (    2017    ,   17520.75    ) ( 2018    ,   18419.25    ) };
    \addlegendentry{\textsc{Microdispensers}}


    \addplot [color=red, fill=red] coordinates
    {(  2012    ,   10482.5 ) ( 2013    ,   11830.25    ) ( 2014    ,   13327.75    ) ( 2015    ,   14825.25    ) ( 2016    ,   16622.25    ) ( 2017    ,   18628.9 ) ( 2018    ,   21114.75    ) };
    \addlegendentry{\textsc{RF MEMS}}


    \addplot [color=orange, fill=orange] coordinates
    {(  2012    ,   10542.4 ) ( 2013    ,   11860.2 ) ( 2014    ,   13447.55    ) ( 2015    ,   14975   ) ( 2016    ,   16921.75    ) ( 2017    ,   19018.25    ) ( 2018    ,   21564   ) };
    \addlegendentry{\textsc{Oscillators}}   


    \addplot [color=black, fill=black] coordinates
    {(  2012    ,   10871.85    )  (    2013    ,   12279.5 ) ( 2014    ,   13777   ) ( 2015    ,   17071.5 ) ( 2016    ,   17371   ) ( 2017    ,   19617.25    ) ( 2018    ,   22312.75    ) };
    \addlegendentry{\textsc{Others}}

    %\legend{InkJet Head, Pressure sensors, Microphones,  Accelerometers, Gyroscopes, Digital compass, Inertial combos, Microbolometers, PIR \& thermopiles, Micro displays, Projection systems, Other optical MEMS, Microfluidics for research, Microfluidics for IVD, Microdispensers, RF MEMS, Oscillators, Others}
    \end{axis}

    \end{tikzpicture}
\end{document}

Bildbeschreibung hier eingeben

Antwort2

Sie können ein wenig mit der Positionierung der Legende experimentieren und die Anzahl der Spalten angeben, die die Legende enthalten soll. Zum Beispiel:

\begin{tikzpicture}
%\*
\begin{axis}[
%
    ybar stacked,
    legend style={legend cell align=left,anchor=north west,,at={(0.0,-0.1)},legend columns=2}, area legend,
        x tick label style={ /pgf/number format/1000 sep=},
    ylabel=Revenue %(\$\,billions),
    enlargelimits=0.05,width=10cm,height=12cm,
    bar width=12pt,
]
    \addplot coordinates
        {(2012,1388) (2013,1388) (2014,1388) (2015,1388) (2016,1388) (2017,1388) (2018,1500)};
        \addlegendentry{\textsc{InkJet Head}} 

    \addplot coordinates
        {(  2012    ,   2995    ) ( 2013    ,   3144.75 ) ( 2014    ,   3294.5  ) ( 2015    ,   2126.45 ) ( 2016    ,   3594    ) ( 2017    ,   3893.5  ) ( 2018    ,   4342.75 ) }; 
        \addlegendentry{\textsc{Pressure sensors}} 

    \addplot  coordinates
        {(  2012    ,   3594    ) ( 2013    ,   3923.45 ) ( 2014    ,   4193    ) ( 2015    ,   4432.6  ) ( 2016    ,   4792    ) ( 2017    ,   5091.5  ) ( 2018    ,   5450.9  ) };
        \addlegendentry{\textsc{Microphones}} 

    \addplot [color=yellow, fill=yellow] coordinates
        {(  2012    ,   5361.05 ) ( 2013    ,   5450.9  ) ( 2014    ,   5690.5  ) ( 2015    ,   5960.05 ) ( 2016    ,   6289.5  ) ( 2017    ,   6529.1  ) ( 2018    ,   6738.75 )};     
        \addlegendentry{\textsc{Accelerometers}} 

    \addplot [color=black, fill=white] coordinates
        {(  2012    ,   6648.9  ) ( 2013    ,   6888.5  )  (    2014    ,   7128.1  ) ( 2015    ,   7188    ) ( 2016    ,   7457.55 ) ( 2017    ,   7637.25 ) ( 2018    ,   7787    )};     
        \addlegendentry{\textsc{Gyroscopes}} 

    \addplot [color=violet, fill=violet] coordinates
        {(  2012    ,   6948.4  ) ( 2013    ,   7337.75 )  (    2014    ,   7547.4  ) ( 2015    ,   7727.1  ) ( 2016    ,   7787    )  (    2017    ,   8086.5  ) ( 2018    ,   8236.25 )};     
        \addlegendentry{\textsc{Digital compass}} 

    \addplot [color=gray, fill=gray] coordinates
        {(  2012    ,   7337.75 ) ( 2013    ,   7906.8  ) ( 2014    ,   8445.9  )  (    2015    ,   9164.7  ) ( 2016    ,   9584) ( 2017    ,   10033.25    ) ( 2018    ,   10482.5 ) };        
        \addlegendentry{\textsc{Inertial combos}} 

    \addplot [color=purple, fill=purple] coordinates
        {(2012,7487.5) (2013,8176.35) (2014,8835.25) (2015,9494.15) (2016,10033.25) (2017,10632.25) (2018,11021.6)};        
        \addlegendentry{\textsc{Microbolometers}} 

    \addplot [color=pink, fill=pink] coordinates
        {(  2012    ,   7547.4  ) ( 2013    ,   8236.25 ) ( 2014    ,   8850.225    ) ( 2015    ,   9509.125    ) ( 2016    ,   10048.225   ) ( 2017    ,   10647.225   ) ( 2018    ,   11081.5 ) };
        \addlegendentry{\textsc{PIR \& thermopiles}} 

    \addplot [color=olive, fill=olive] coordinates
        {(  2012    ,   7562.375    ) ( 2013    ,   8251.225    ) ( 2014    ,   8865.2  ) ( 2015    ,   9524.1  ) ( 2016    ,   10063.2 ) ( 2017    ,   10662.2 ) ( 2018    ,   11096.475   ) };
        \addlegendentry{\textsc{Micro displays}} 

    \addplot [color=magenta, fill=magenta] coordinates
        {(  2012    ,   8386    ) ( 2013    ,   9134.75 ) ( 2014    ,   10033.25    ) ( 2015    ,   10886.825   ) ( 2016    ,   11740.4 ) ( 2017    ,   12608.95    ) ( 2018    ,   13477.5 ) };
        \addlegendentry{\textsc{Projection systems}}

    \addplot [color=lime, fill=lime] coordinates
        {(  2012    ,   8685.5  ) ( 2013    ,   9434.25 ) ( 2014    ,   10332.75    )  (    2015    ,   11081.5 ) ( 2016    ,   12129.75    ) ( 2017    ,   12938.4 ) ( 2018    ,   13926.75    ) };
        \addlegendentry{\textsc{Other optical MEMS}}

    \addplot [color=green, fill=green] coordinates
        {(  2012    ,   8985    ) ( 2013    ,   10003.3 ) ( 2014    ,   10931.75    ) ( 2015    ,   12219.6 ) ( 2016    ,   13417.6 ) ( 2017    ,   14825.25    ) ( 2018    ,   16472.5 ) };
        \addlegendentry{\textsc{Microfluidics for research}} 

    \addplot [color=cyan, fill=cyan] coordinates
        {(  2012    ,   9823.6  ) ( 2013    ,   10931.75    ) ( 2014    ,   12129.75    ) ( 2015    ,   13537.4 ) ( 2016    ,   15124.75    ) ( 2017    ,   16831.9 ) ( 2018    ,   19018.25    ) };
        \addlegendentry{\textsc{Microfluidics for IVD}}

    \addplot [color=brown, fill=brown] coordinates
        {(  2012    ,   10123.1 ) ( 2013    ,   11231.25    ) ( 2014    ,   12579   ) ( 2015    ,   14076.5 ) ( 2016    ,   15723.75    )  (    2017    ,   17520.75    ) ( 2018    ,   18419.25    ) };
        \addlegendentry{\textsc{Microdispensers}}

    \addplot [color=red, fill=red] coordinates
        {(  2012    ,   10482.5 ) ( 2013    ,   11830.25    ) ( 2014    ,   13327.75    ) ( 2015    ,   14825.25    ) ( 2016    ,   16622.25    ) ( 2017    ,   18628.9 ) ( 2018    ,   21114.75    ) };
        \addlegendentry{\textsc{RF MEMS}}

    \addplot [color=orange, fill=orange] coordinates
        {(  2012    ,   10542.4 ) ( 2013    ,   11860.2 ) ( 2014    ,   13447.55    ) ( 2015    ,   14975   ) ( 2016    ,   16921.75    ) ( 2017    ,   19018.25    ) ( 2018    ,   21564   ) };
        \addlegendentry{\textsc{Oscillators}}   

    \addplot [color=black, fill=black] coordinates
        {(  2012    ,   10871.85    )  (    2013    ,   12279.5 ) ( 2014    ,   13777   ) ( 2015    ,   17071.5 ) ( 2016    ,   17371   ) ( 2017    ,   19617.25    ) ( 2018    ,   22312.75    ) };
        \addlegendentry{\textsc{Others}}

%\legend{InkJet Head, Pressure sensors, Microphones,  Accelerometers, Gyroscopes, Digital compass, Inertial combos, Microbolometers, PIR \& thermopiles, Micro displays, Projection systems, Other optical MEMS, Microfluidics for research, Microfluidics for IVD, Microdispensers, RF MEMS, Oscillators, Others}
    \end{axis}
%*/
\end{tikzpicture}

Dies ist jedoch nicht genau das Modell Ihrer Frage, da die Anzahl der Einträge pro Zeile festgelegt ist ...

verwandte Informationen