I would like to create a bar chart using tikz. I want it to look like that:
but when I added the data, I got something like that:
Is there a way to enlarge the x-axis over the textwidth or some other way to fix it? I would like the text to stay at this size.
Here is my code:
\begin{tikzpicture}
\begin{axis}[
compat=newest,
legend style={at={(0.5,-0.15)},
anchor=north,legend columns=-1},
ybar,
bar width=10pt,
%
point meta=rawy,
%
axis x line=bottom,
axis y line=left,
ymajorgrids=true,
grid style=dashed,
%
ylabel=[MWh],
ymin=0,
scaled ticks=false,
tick label style={/pgf/number format/fixed},
enlargelimits=auto,
enlarge x limits=0.2,
%
symbolic x coords ={2021, 2022, 2023, 2024, 2025,2026,2027,2028,2029,2030,2031,2032,2033,2034,2035,2036},
%x tick label style={rotate=30,anchor=north east},
xtick distance=1,
/pgf/number format/.cd,
use comma,
1000 sep={.}
]
\addplot[fill=Grey] coordinates {
(2021,232)
(2022,224)
(2023,216)
(2024,208 )
(2025, 200)
(2026,192)
(2027,184)
(2028,176)
(2029,168)
(2030,160)
(2031, 152)
(2032,144)
(2033,136)
(2034, 128)
(2035,120)
(2036,112)
};
\addplot[fill=LightBlue] coordinates {
(2021,198)
(2022,193)
(2023,188)
(2024,182)
(2025,177)
(2026,172)
(2027,167)
(2028,162)
(2029,157)
(2030,152)
(2031,147)
(2032,142)
(2033,137)
(2034, 132)
(2035,127)
(2036, 122 )
};
\addplot[fill=Blue] coordinates {
(2021,122)
(2022,134)
(2023,147)
(2024,160)
(2025,172)
(2026,185)
(2027,198)
(2028,210)
(2029,223)
(2030, 236)
(2031, 248)
(2032,261)
(2033,274)
(2034, 287)
(2035,299)
(2036,312)
};
\addplot[fill=DarkBlue] coordinates {
(2021,300)
(2022,317)
(2023,335)
(2024,353)
(2025,370)
(2026,388)
(2027,405)
(2028, 423)
(2029, 441)
(2030,458)
(2031, 476)
(2032, 493)
(2033,511)
(2034,528)
(2035, 546)
(2036,564)
};
\legend{Option 1, Option 2, Option 3, Option 4}
\end{axis}
\end{tikzpicture}
I'm sorry, if the question has been asked before, I just couldn't find anything that fit my answer. Thanks in advance!
width=0.9\textwidth
and/orheight=<length>
in theaxis
options. If you only specify one the aspect ratio remains the same. Quite possibly a duplicate can be found, if not me (or whoever else feels like doing so) can add an answer later.