How to correct problem with ybar plot: bad axis and too many labels in x axis

1,195

Perhaps this approach is somewhat useful for you. The axes are put at the left and bottom and there is a minor grid for the y ticks. There are no symbolic x coords anymore and instead you now have explicit xticklabels. The double first and last ticks are gone.

The chemical compounds in the ticks of the abscissa have been formatted by »chemformula« from the »chemmacros« bundle. The »siunitx« package helps to format the unit for the label of the ordinate.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}
\usepackage{chemformula}

\usepackage{siunitx}
\sisetup{
  inter-unit-product = \ensuremath{{}\cdot{}},
  per-mode=fraction
}

\pgfplotsset{compat=1.9}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
      width=14cm,
      height=7cm,
      axis x line*=bottom,
      axis y line*=left,
      nodes near coords,
      legend style={
        at={(0.5,-0.15)},
        anchor=north,
        legend columns=-1
      },
      xtick={1,2,...,12},
      xticklabels={\ch{AL2O3},\ch{ALN},\ch{Si3N4},\ch{BeO},Epoxid,Polyimid,\ch{ALSiC},\ch{Al},\ch{Cu},\ch{Mo},\ch{Si},\ch{Au}},
      x tick label style={rotate=90,anchor=east},
      ymin=0,
      ymax=500,
      ybar=5pt,
      bar width=0.4cm,
      ylabel={Thermoconductivity / \si{\W\per\m\per\K}},
      ymajorgrids=true,
      ytick={100,200,...,500}
    ]
      \addplot[color=black,fill=lightgray,ybar legend] coordinates {
        (1,24)
        (2,180)
        (3,70)
        (4,250)
        (5,3)
        (6,0.385)
        (7,200)
        (8,237)
        (9,394)
        (10,138)
        (11,148)
        (12,317)
      };
    \end{axis}
  \end{tikzpicture}
\end{document}

enter image description here

Share:
1,195
quantumflight
Author by

quantumflight

Updated on December 09, 2020

Comments

  • quantumflight
    quantumflight almost 3 years

    I need a bit of help here with the axis... Any suggestions would be always welcome. I have got 2 extra labels at the x axis...

     \documentclass{scrreprt}
    
     \usepackage{pgfplots}
     \usepgflibrary{decorations.markings}
     \usepackage{tikz}
     \usetikzlibrary{arrows,decorations.pathmorphing,backgrounds,positioning,fit,petri     }
     \usepackage{textcomp}
    
     \begin{document}
    
     \begin{tikzpicture}
     \begin{axis}[
     symbolic x coords={AL2O3, ALN, Si3N4, BeO, Epoxid, Polimid, ALSiC, Al, Cu,      Mo, Si, Au},
     width=15cm,
     height=5cm,
     %xtick={200,400},
     %grid=major,
     x tick label style={rotate=90,anchor=east},
     ylabel=$\mathbf{W/m\cdot K}$,
     enlargelimits=0.15,
     legend style={at={(0.5,-0.15)},
     anchor=north,legend columns=-1},
     ybar=5pt,% configures `bar shift'
     ymin=0,
     ymax=500,
     bar width=0.4cm,
     nodes near coords,
     ]
     \addplot[color=black, fill=lightgray, ybar legend]
     coordinates {(AL2O3,24) (ALN,180) (Si3N4,70) (BeO,250) (Epoxid,3.0)      (Polimid,0.385) (ALSiC,200) (Al,237) (Cu,394) (Mo,138) (Si,148) (Au,317)};
     \end{axis}
     \end{tikzpicture}
     \end{document}
    

    Somehow I would like to have a minor grid at the y axis, and that it starts at 0 along with the x axis, and that the upper axis doesn't have a cross...

    • Fran
      Fran about 10 years
      Welcome to TeX.sx! Please always add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}.
    • Jake
      Jake about 10 years
      What exactly is your question?
    • Fran
      Fran about 10 years
      Usually, we don't put a greeting or a “thank you” in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say “thank you” to users who helped you.
    • Thorsten Donig
      Thorsten Donig about 10 years
      What does "upper axis doesn't have a cross" mean?
    • quantumflight
      quantumflight about 10 years
      @ThorstenDonig it should mean that the marks at the upper horizontal axis atays just in the box... I believe that is made with xtick{}, but I´m not sure...
    • Thorsten Donig
      Thorsten Donig almost 10 years
      No good idea. Imagine a situation where one or more bars go beyond the upper limit of the y domain. Then it would be good to have the ticks outside the axes for better orientation