3

I would like a plot like the one here shown (wanted) As using ybar, the origin is fixed at 0, I'm getting a plot with the bars starting from zero instead of -120.

bar chart wanted from MSexcel

4
  • 1
    You mean the problem is about representation of [-120,-90] ? So your Y-axis is not in this range ? Could you show us some codes ? Sep 15, 2016 at 18:28
  • ploting this using tikzpicture \ybar I m getting bar whichs start from 0, instead from -120.
    – Andrew
    Sep 15, 2016 at 18:50
  • You want to change the sign of your data ?
    – percusse
    Sep 16, 2016 at 7:59
  • Can you post the code for your plot as a MWE? Sep 16, 2016 at 7:59

2 Answers 2

2

You can shift the labels with an offset

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.14}
\pgfplotstableread{
a b c
1 10 20
2 45 130
3 30 60
}\mytable
\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar,xtick=data,enlarge y limits={upper=5},ymin=0,
yticklabel={\pgfmathparse{\tick-120}\pgfmathprintnumber{\pgfmathresult}}]
\addplot table[x=a,y=b] {\mytable};
\addplot table[x=a,y=c] {\mytable};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

1

You can use ymax and ymin in the axis properties. Consider following samples. Without setting parameters (Commented lines):

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    ybar=15,            
    %ymin=0,
    %ymax=120,            
    symbolic x coords={a small bar,a medium bar,a large bar},
    xtick=data]
    \addplot[ybar,fill=blue] coordinates {
        (a small bar,42)
        (a medium bar,50)
        (a large bar,80)
    };
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

Uncomment the lines and you will have different ranges for Y-axis:

enter image description here

3
  • getting same results with your code. Bars should be draw from -120 up to data level.
    – Andrew
    Sep 15, 2016 at 19:50
  • You can change the ymax and ymin value according to your problem. Sep 15, 2016 at 19:55
  • thank you. but the problem is not range, but the bar origin point. Changing range will not affect the the bar origin, always they start from 0. The wanted chart is with bar staring from another value eg -120.
    – Andrew
    Sep 16, 2016 at 3:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.