TransWikia.com

pgfplots axis labels with variable scale and abbreviation

TeX - LaTeX Asked by Matheus Leão on April 15, 2021

After a bit a research, I’m using this solution to abbreviate my y-axis labels. However, this only allows me to set a single abbreviation. My data spans multiple orders of magnitude, and I’d like to abbreviate each accordingly.

documentclass{article}
usepackage{pgfplots}
pgfplotsset{compat=1.17}

begin{document}
definecolor{bblue}{HTML}{4F81BD}
definecolor{rred}{HTML}{C0504D}
begin{tikzpicture}
    begin{axis}[
        width = 0.85*textwidth,
        height = 8cm,
        major x tick style = transparent,
        ybar = 2*pgflinewidth,
        bar width = 10pt,
        ymajorgrids = true,
        ylabel = {Gastos Totais (R$)},
        symbolic x coords={2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020},
        y coord trafo/.code={pgfmathparse{pgfmathresult/1000000}},
        yticklabel = pgfmathprintnumber{tick},mi,
        xtick = data,
        scaled y ticks = false,
        enlarge x limits = 0.10,
        ymin = 0,
        legend cell align = left,
        legend style={
                at={(1,1.05)},
                anchor=south east,
                column sep = 1ex
        },
        /pgf/number format/.cd,
            use comma,
            1000 sep = {.}
        ]
        addplot[style={bblue,fill=bblue,mark=none}]
            coordinates {(2010, 134148978.40)
                         (2011, 163850342.64)
                         (2012, 189780916.97)
                         (2013, 226166578.45)
                         (2014, 246515645.81)
                         (2015, 313435568.42)
                         (2016, 321922725.99)
                         (2017, 351241496.32)
                         (2018, 348859916.86)
                         (2019, 464608106.68)
                         (2020, 316765254.56)};
        addplot[style={rred,fill=rred,mark=none}]
            coordinates {(2010, 584857230.67)
                         (2011, 633624150.04)
                         (2012, 675257494.54)
                         (2013, 730684305.39)
                         (2014, 837961674.33)
                         (2015, 890103343.15)
                         (2016, 937943259.40)
                         (2017, 988067801.53)
                         (2018, 1043622588.84)
                         (2019, 1264544768.36)
                         (2020, 844383399.89)};
        legend{Defensoria Pública,Ministério Público}
    end{axis}
end{tikzpicture}

end{document}

This produces the following graph:
enter image description here

How can I make it so that the zero appears without any extra label (just "0") and the billions appear instead scaled by another 1000 and with the abbreviation "bi"?

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP