Graphics, Figures & Tables ⇒ pst-plot | Costumize Bar Plot
- svend_tveskaeg
- Posts: 478
- Joined: Sun Jul 12, 2009 5:31 am
pst-plot | Costumize Bar Plot
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!
-- Zapp Brannigan, Futurama (season 1, episode 4)
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
Thorsten
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
- svend_tveskaeg
- Posts: 478
- Joined: Sun Jul 12, 2009 5:31 am
pst-plot | Costumize Bar Plot
plotstyle=values
. Any solution regarding the other issue will be most welcome.Thanks a bunch!
-- Zapp Brannigan, Futurama (season 1, episode 4)
- localghost
- Site Moderator
- Posts: 9202
- Joined: Fri Feb 02, 2007 12:06 pm
pst-plot | Costumize Bar Plot
That's one of the reasons why reading a package manual should be the first step towards a solution.svend_tveskaeg wrote:[…] Nice. I did not knew about the option […]
At the moment I don't have the slightest idea.svend_tveskaeg wrote:[…] Any solution regarding the other issue will be most welcome. […]
Board Rules
Avoidable Mistakes
¹ System: TeX Live 2025 (vanilla), TeXworks 0.6.10
- svend_tveskaeg
- Posts: 478
- Joined: Sun Jul 12, 2009 5:31 am
pst-plot | Costumize Bar Plot
Regarding the other issue: I am wondering if something like
\psIntersectionPoint
from the 
-- Zapp Brannigan, Futurama (season 1, episode 4)
- svend_tveskaeg
- Posts: 478
- Joined: Sun Jul 12, 2009 5:31 am
pst-plot | Costumize Bar Plot
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}
(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}
-- Zapp Brannigan, Futurama (season 1, episode 4)
-
- Posts: 351
- Joined: Sat Aug 02, 2008 8:47 am
pst-plot | Costumize Bar Plot
PostScript knows the fonts Times, New Century Schoolbook, Palatinosvend_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 thePSfont
option but I could not find anything useful.)
See manual. Use one of these fonts in your document, too
- svend_tveskaeg
- Posts: 478
- Joined: Sun Jul 12, 2009 5:31 am
Re: pst-plot | Costumize Bar Plot
@Herbert: Do you have any tricks regarding the plotting of the bars?
-- Zapp Brannigan, Futurama (season 1, episode 4)
-
- Posts: 351
- Joined: Sat Aug 02, 2008 8:47 am
pst-plot | Costumize Bar Plot
what do you mean with tricks? pst-plot already knows the plotstyle barsvend_tveskaeg wrote:Okay. Thank you.
@Herbert: Do you have any tricks regarding the plotting of the bars?
- svend_tveskaeg
- Posts: 478
- Joined: Sun Jul 12, 2009 5:31 am
pst-plot | Costumize Bar Plot
The first part is okay (except of the decimal points instead of integers) but the second part seems not to be directly possible with thesvend_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)?

My solution does not seems elegant at all.
-- Zapp Brannigan, Futurama (season 1, episode 4)