I am having trouble with my tikz plotenter image description here, Even the value is 21508 corresponding to drive, it is evident from the figure that histogram is not scaled properly. I do not know why this is happening.

My code is attached:



         \begin{axis}[title= \textbf{Before Simplification},
                scaled ticks=false, 
                tick label style={/pgf/number format/fixed},
                xbar ,
                enlarge y limits=0.15,
                enlarge x limits={upper, value=0.15},
                y axis line style = { opacity = 0 },
               axis x line       = none,
               tickwidth         = 0pt,
               bar width=0.3cm,
               nodes near coords={
        nodes near coords align={horizontal},
        symbolic y coords = {drive,drive-service,walk,bike,all,all-private},
        legend pos = outer north east,] 
        \addplot [draw=blue,pattern=horizontal lines light blue] 
         coordinates {(21508,drive) (31963,drive-service) (47924,walk) (43923,bike) (53370,all) (56120,all-private)};

What am I doing wrong?

  • Welcome to TeX.SX! It can be easily seen that in each bar, a length of 21508 is cut - and that is the problem. Anyway, please expand your code snippet to a compilable minimal working example so that others can compile it and make some changes thus it is easier to help you.
    – user156344
    Dec 27 '18 at 9:45
  • The scaling is probably right, it's just that the diagram starts at 21508.
    – moewe
    Dec 27 '18 at 16:31

Edit: as observed by @moewe, insert xmin=0 to have all bars proportional.

enter image description here

  • I guess the OP actually wants the bars to start at 0 so that the lengths of the bars are proportional to the values. That still does not seem to be the case with this solution.
    – moewe
    Dec 27 '18 at 16:31
  • The cheap solution is to add xmin=0, but real TikZ/pgfplots experts may have better ideas than that.
    – moewe
    Dec 27 '18 at 16:34
  • @moewe, I edited, if you don't mind. If you wish, post an answer and I'll be glad to delete mine.
    – Sigur
    Dec 27 '18 at 16:38
  • Fine by me. ...
    – moewe
    Dec 27 '18 at 16:43
  • Adding the xmin=0 helped to solve the problem. But I am open to other solutions too Thanks Dec 27 '18 at 18:46

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.