Graphics, Figures & Tables ⇒ Modifying axis names in bar plots
Modifying axis names in bar plots
Hi,
how can I change the lables of the x-axis as shown in the attached bar-plot in tikz or pgfplot?
Thanks
how can I change the lables of the x-axis as shown in the attached bar-plot in tikz or pgfplot?
Thanks
- Attachments
-
- Mass_contribution_of_each_species.jpg (23.14 KiB) Viewed 4248 times
NEW: TikZ book now 40% off at Amazon.com for a short time.

- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Modifying axis names in bar plots
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Modifying axis names in bar plots
Hi
I wrote the following code:
But it is giving me the following output
What am I doing wrong?
I wrote the following code:
Code: Select all
\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}
\begin{axis}[ybar]
xticklabels={$N2$,$O2$,$H20 $,$CO2 $,$CH4 $,$CO $,$OH $,$O $,$CH2O $,$H2$}
xticks={0,1,2,3,4,5,6,7,8,9}
\addplot[draw=blue,fill=blue] plot
coordinates {
(0,42.51)
(1,35.98)
(2,10.41)
(3,5.49)
(4,2.38)
(5,0.87)
(6,0.6)
(7,0.49)
(8,0.38)
(9,0.317)
};
\end{axis}
\end{tikzpicture}
\end{document}
Last edited by jhapk on Thu Jul 29, 2010 11:35 pm, edited 1 time in total.
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Modifying axis names in bar plots
I don't think that you tested the example you provided. It doesn't work at all. So you still have to learn how to build a minimal working example (MWE).
Code: Select all
\documentclass{article}
\usepackage{pgfplots}
\usepackage[version=3]{mhchem}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
font=\scriptsize,
width=10cm,height=7cm,
xtick={0,1,...,9},
xticklabels={\ce{N2},\ce{O2},\ce{H2O},\ce{CO2},\ce{CH4},\ce{CO},\ce{OH},\ce{O},\ce{CH2O},\ce{H2}},
ylabel={Percentage contribution to total mass (\%)},
extra description/.code={\node[left] at (0.95,0.9) {Total contribution$=$99,427\%};}
]
\addplot[ybar,draw=blue,fill=blue] plot coordinates {%
(0,42.51)
(1,35.98)
(2,10.41)
(3,5.49)
(4,2.38)
(5,0.87)
(6,0.6)
(7,0.49)
(8,0.38)
(9,0.317)
};
\end{axis}
\end{tikzpicture}
\end{document}
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: Modifying axis names in bar plots
Hi,
sorry about the error in my code. I will be more careful from hereon.
One more question, How do I turn off the yticks and change the spacing of Ylabel?
sorry about the error in my code. I will be more careful from hereon.
One more question, How do I turn off the yticks and change the spacing of Ylabel?
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
Modifying axis names in bar plots
This can be answered with a nice acronym: RTFM. But since we have come so far we just supplement the code from above and present it here.jhapk wrote:[...] How do I turn off the yticks and change the spacing of Ylabel?
Code: Select all
\documentclass{article}
\usepackage{pgfplots}
\usepackage[version=3]{mhchem}
\pagestyle{empty}
\pgfplotsset{%
every axis y label/.style={%
at={(0,0.5)},
xshift=-10pt,
rotate=90
}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
font=\scriptsize,
width=10cm,height=7cm,
xtick={0,1,...,9},
ytick=\empty,
xticklabels={\ce{N2},\ce{O2},\ce{H2O},\ce{CO2},\ce{CH4},\ce{CO},\ce{OH},\ce{O},\ce{CH2O},\ce{H2}},
ylabel={Percentage contribution to total mass (\%)},
extra description/.code={\node[left] at (0.95,0.9) {Total contribution$=$99,427\%};}
]
\addplot[ybar,draw=blue,fill=blue] plot coordinates {%
(0,42.51)
(1,35.98)
(2,10.41)
(3,5.49)
(4,2.38)
(5,0.87)
(6,0.6)
(7,0.49)
(8,0.38)
(9,0.317)
};
\end{axis}
\end{tikzpicture}
\end{document}
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
Re: Modifying axis names in bar plots
Thanks a lot Localghost. That worked.