[pstricks] Transformation into bar chart

Herbert Voss Herbert.Voss at alumni.TU-Berlin.DE
Wed Sep 1 09:20:00 CEST 2004


Matthias Steinbrink wrote:

> Unfortunately I actually meant something like a "real" bar diagramm, a 
> bit like example bsp08 in your book. And I thought that there might be 
> an easy way of achieving this without the need of hard-coding the bar 
> length.

Then try this. barwidth is the absolute width of the bar

Herbert



\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{Daten.data}
0 0.03
1 0.11
2 0.28
3 0.84
4 6.70
5 8.55
6 8.77
7 11.09
8 7.18
9 6.20
10 5.78
11 4.19
12 2.37
13 2.26
14 1.68
15 1.03
16 1.37
17 1.34
18 0.92
19 0.67
20 0.87
21 1.20
22 1.98
23 3.99
24 5.08
25 5.17
26 5.78
27 4.44
28 0.11
\end{filecontents*}
\usepackage{pstricks,pst-plot,pstricks-add}
\makeatletter
\def\psset at barwidth#1{\pst at getlength{#1}\psk at barwidth}
\psset at barwidth{0.25cm}
%
\def\psbar at ii{%
   \addto at pscode{false \tx at NArray \psbar at iii}%
   \end at SpecialObj%
}
\def\psbar at iii{%
   \pst at number\pslinewidth SLW
   newpath
   n {
   \pst at usecolor\pslinecolor
   /Y exch def /X exch def
   X \number\psk at barwidth sub 0 moveto
   0 Y rlineto \number\psk at barwidth 0 rlineto 0 Y neg rlineto
   \pst at usecolor\psfillcolor
   fill
} repeat}
%
\def\beginplot at bar{\begin at SpecialObj}
\def\endplot at bar{\psbar at ii}
\def\beginqp at bar{%
   \@nameuse{psds@\psk at linestyle}
}
\def\doqp at bar{psBar }
\def\endqp at Bar{\end at SpecialObj}
\def\testqp at Bar{\@psttrue}
%
\makeatother

\begin{document}
   \psset{xunit=.22cm,yunit=.3cm}
   \begin{figure}[h]
     \begin{center}
       \begin{pspicture}(-5.5,-1.5)(29,13)
         \psaxes[axesstyle=axes,%
                    Ox=1466,Oy=0,Dx=4,Dy=2,%
                    ylabelFactor={\,\%}]{-}(29,12)
         \readdata{\data}{Daten.data}
         \listplot[plotstyle=bar,barwidth=0.15cm,
             fillcolor=blue,fillstyle=solid]{\data}
         \rput{90}(-5.5,6.25){Amount}
      \end{pspicture}
     \end{center}
   \end{figure}
\end{document}



-- 
http://TeXnik.de/
http://PSTricks.de/
ftp://ftp.dante.de/tex-archive/info/math/voss/Voss-Mathmode.pdf
http://www.dante.de/faq/de-tex-faq/
http://www.tex.ac.uk/cgi-bin/texfaq2html?introduction=yes




More information about the PSTricks mailing list