4

I did my first box with pgfplots package. I have several questions :

How to write numbers without commas with a thousands separator ?

How to have a larger distance between the box and the x axis ?

\usemodule[tikz]
\usemodule[pgfplots]
\usepgfplotslibrary[statistics]
\pgfplotsset[width=12cm,compat=1.11]

\starttext

\starttikzpicture
\startaxis[y=1.5cm,
       axis y line=none,
       axis x line=bottom,
       enlarge x limits,
       thick
      ]

\addplot+[
          green,line width=0.5mm,
          boxplot prepared={
          median=1500,
          upper quartile=2500,
          lower quartile=1200,
          upper whisker=3000,
          lower whisker=1000
           },
          ] coordinates {};

\stopaxis
\stoptikzpicture
\stoptext

enter image description here

Fabrice
  • 3,636
  • 1
  • 21
  • 29

1 Answers1

6

Your first question can be answered by a number of posts on this site, e.g., number format in pgfplots axis. The simple solution is to add code for number formatting to your axis labels:

/pgf/number format/1000 sep={}

Your second question can be resolved by setting ymin=0 (or really, any ymin value, 0 happens to be a good choice IMHO).

I would note that the \pgfplotsset line was giving errors for me, but I have no experience with context so I can't be sure what was causing the error.

The error on that line was due to using square braces instead of curly braces around the options. If I correct the error, the default ticks are overlapping, so in the code below is a specification of a reasonable number of ticks. You should change this as you see fit.

Finally, I prefer to end each line of the options (even the last one) with a comma. This makes adding new lines to the options easier - I don't have to remember to add a comma, and my version control only tells me that one line has changed, instead of two. So you'll see that here, but its purely personal preference :-)

\usemodule[tikz]
\usemodule[pgfplots]
\usepgfplotslibrary[statistics]
\pgfplotsset{width=12cm, compat=1.11}

\starttext

\starttikzpicture
\startaxis[y=1.5cm,
       axis y line=none,
       axis x line=bottom,
       enlarge x limits,
       thick,
       x tick label style={
           /pgf/number format/1000 sep={}
       },
       xtick={800,1200,...,3200},
       ymin=0,
      ]

\addplot+[
          green,line width=0.5mm,
          boxplot prepared={
          median=1500,
          upper quartile=2500,
          lower quartile=1200,
          upper whisker=3000,
          lower whisker=1000,
           },
          ] coordinates {};

\stopaxis
\stoptikzpicture
\stoptext

enter image description here

darthbith
  • 7,384
  • @ darthbith Sorry for the late reply, much work ! Thank you, it is very clear, but my learning of TikZ will be longer than Metapost or PSTricks. – Fabrice Jan 19 '15 at 15:21
  • @Fabrice You're welcome, no problem. TikZ is a very large package, for sure :-) – darthbith Jan 19 '15 at 15:51