Graphics, Figures & Tablespst-plot | Costumize Bar Plot

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

pst-plot | Costumize Bar Plot

Post by svend_tveskaeg »

Hi all.

Assume I want to create a bar plot. Is it possible to add the absolute value for each bar on top of the respective bar and the relative value for each bar at the center of the respective bar (i.e., at the intersection point for the two diagonals in the bar)?

I hope this makes sense.

Thank you in advance!
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

pst-plot | Costumize Bar Plot

Post by localghost »

For the absolute values on top of a bar take a look at Section 12.3 of the pst-plot manual.


Thorsten
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

pst-plot | Costumize Bar Plot

Post by svend_tveskaeg »

@Thorsten: Nice. I did not knew about the option plotstyle=values. Any solution regarding the other issue will be most welcome.

Thanks a bunch!
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

pst-plot | Costumize Bar Plot

Post by localghost »

svend_tveskaeg wrote:[…] Nice. I did not knew about the option […]
That's one of the reasons why reading a package manual should be the first step towards a solution.
svend_tveskaeg wrote:[…] Any solution regarding the other issue will be most welcome. […]
At the moment I don't have the slightest idea.
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

pst-plot | Costumize Bar Plot

Post by svend_tveskaeg »

I have had a look at the manual; I simply missed it so thank you for pointing me to it.

Regarding the other issue: I am wondering if something like \psIntersectionPoint from the pstricks-add package (section 18) is useful to find the intersection point of the diagonals. (Some macro "home-cooking" seems to be necessary.)
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

pst-plot | Costumize Bar Plot

Post by svend_tveskaeg »

Here is what I have so far (I have not tried the bar customization yet):

Code: Select all

\documentclass[danish]{article}
\usepackage{babel}
\usepackage[margin=3cm]{geometry}
\usepackage{pst-plot}

% ``0'' as first label on the y-axis. (Thanks to Herbert Voss.)
\makeatletter
 \def\pst@@@vlabel#1{%
   \edef\@xyDecimals{\psk@yDecimals}%
   \ifodd\psk@labels % labelss=all||y (0,2)
   \else%
     \ifnum#1=0 \psvlabel{\expandafter\@LabelComma#1..\@nil}%
     \else \psvlabel{\expandafter\@LabelComma#1..\@nil\psk@ylabelFactor}%
     \fi
   \fi%
}%
\makeatother

\begin{document}

\begin{figure}[htbp]
\centering
\begin{pspicture}(10cm,10cm)
\savedata{\data}[{1,86},{3,87},{5,107},{7,147},{9,102},{11,125},{13,16},{15,210}]
\psset{unit=0.9cm,xAxisLabel={Tv-stationer},yAxisLabel={Seertal}}
\begin{psgraph}[xLabelsRot=90,
  xLabels={,Nord,,Midt-Vest,,{\O}stjylland,,Syd,,Fyn,,{\O}st,,Bornholm,,Lorry,},
Dy=25,ticks=y,ylabelFactor={\cdot 10^3}](0,0)(0,0)(16,235){10cm}{10cm}
\psaxes[xAxis=false,ticks=none,labels=none]{->}(0,0)(16,235)
\listplot[plotstyle=bar]{\data}
\listplot[plotstyle=values]{\data}
\end{psgraph}
\end{pspicture}
\end{figure}

\end{document}
Issues:
(1) The values on top of the bars are offset to the right.
(2) The values on top of the bars should be integers instead of decimal points.
(3) Can I have the values printed in the same font as the rest of the figure? (I have had a look at the PSfont option but I could not find anything useful.)

Update
Here is a try but the plot can almost certainly be created (a lot) more elegantly:

Code: Select all

\documentclass[danish]{article}
\usepackage{babel}
\usepackage[margin=3cm]{geometry}
\usepackage{pst-plot}
\usepackage[locale=DE]{siunitx}

% ``0'' as first label on the y-axis. (Thanks to Herbert Voss.)
\makeatletter
 \def\pst@@@vlabel#1{%
   \edef\@xyDecimals{\psk@yDecimals}%
   \ifodd\psk@labels % labelss=all||y (0,2)
   \else%
     \ifnum#1=0 \psvlabel{\expandafter\@LabelComma#1..\@nil}%
     \else \psvlabel{\expandafter\@LabelComma#1..\@nil\psk@ylabelFactor}%
     \fi
   \fi%
}%
\makeatother

% The bars.
\def\width{0.7 }
\newcommand*{\seere}[3]{%
  \pspolygon[fillstyle=solid,fillcolor=blue!50]%
    (!2 #1 mul 1 sub \width 2 div sub 0)%
    (!2 #1 mul 1 sub \width 2 div sub #2)%
    (!2 #1 mul 1 sub \width 2 div add #2)%
    (!2 #1 mul 1 sub \width 2 div add 0)%
  \rput{0}(!2 #1 mul 1 sub #2 5 add){\small{\num{#2 000}}}%
  \rput{90}(!2 #1 mul 1 sub #2 2 div){\small{\SI{#3}{\percent}}}%
}

\begin{document}

\begin{figure}[htbp]
\centering
\psset{xunit=0.7cm,yunit=0.05cm}
\begin{pspicture}(20,240)
\psaxes[xLabels={,Nord,,Midt-Vest,,{\O}stjylland,,Syd,,Fyn,,{\O}st,,Bornholm,,Lorry,},
xLabelsRot=90,Dy=2,dy=20,ticks=y,ylabelFactor={\cdot 10^4}]{->}(0,0)(16,230)%
[Tv-stationer,0][Seere,90]
\multido{\i=20+20}{11}{\psline[linestyle=dotted](0,\i)(16,\i)}
\seere{1}{86}{9.8}
\seere{2}{87}{9.9}
\seere{3}{107}{12.2}
\seere{4}{147}{16.7}
\seere{5}{102}{11.6}
\seere{6}{125}{14.2}
\seere{7}{16}{1.8}
\seere{8}{210}{23.9}
\end{pspicture}
\end{figure}

\end{document}
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

pst-plot | Costumize Bar Plot

Post by CrazyHorse »

svend_tveskaeg wrote: Issues:
(3) Can I have the values printed in the same font as the rest of the figure? (I have had a look at the PSfont option but I could not find anything useful.)
PostScript knows the fonts Times, New Century Schoolbook, Palatino
See manual. Use one of these fonts in your document, too
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Re: pst-plot | Costumize Bar Plot

Post by svend_tveskaeg »

Okay. Thank you.

@Herbert: Do you have any tricks regarding the plotting of the bars?
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
CrazyHorse
Posts: 351
Joined: Sat Aug 02, 2008 8:47 am

pst-plot | Costumize Bar Plot

Post by CrazyHorse »

svend_tveskaeg wrote:Okay. Thank you.

@Herbert: Do you have any tricks regarding the plotting of the bars?
what do you mean with tricks? pst-plot already knows the plotstyle bar
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

pst-plot | Costumize Bar Plot

Post by svend_tveskaeg »

svend_tveskaeg wrote:Is it possible to add the absolute value for each bar on top of the respective bar and the relative value for each bar at the center of the respective bar (i.e., at the intersection point for the two diagonals in the bar)?
The first part is okay (except of the decimal points instead of integers) but the second part seems not to be directly possible with the pst-plot package, unless I am missing something in the manual.

My solution does not seems elegant at all.
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
Post Reply