Graphics, Figures & TablesGnuplot: Histogram bars all black & chart offset to axes

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
jason2
Posts: 10
Joined: Fri Sep 24, 2010 1:47 am

Gnuplot: Histogram bars all black & chart offset to axes

Post by jason2 »

Hi,

I am trying to make a simple stacked histogram. I am having two problems:
1) The histogram bars are completely solid black, making it impossible to distinguish the stacked items.
2) The chart is offset from the axes.

I am using the working example provided by the folks at Code Alias. The link to their tutorial is here: http://www.codealias.info/technotes/gnu ... am_example

Their data file is as follows:

Code: Select all

1 23 2 9 13
2 25 5 7 12
3 26 5 3 13
4 20 6 8 5
5 23 5 12 15
6 23 5 12 11
7 22 9 12 5
8 24 16 5 8
9 23 2 12 10
10 23 15 5 9
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
And their minimal working example is:

Code: Select all

set terminal epslatex 8
set output 'histo.eps'
set boxwidth 0.75 absolute
set style fill solid 1.00 border -1
set style histogram rowstacked
set style data histograms
set xtics 1000 nomirror
set ytics 100 nomirror
set mxtics 2
set mytics 2
set ytics 10
set yrange [0:50]
set ylabel "Total time"
set xlabel "Session number"
plot 'data' using 3 t "Server", '' using 4 t "Client", '' using 5:xtic(1) t "Network"
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
I've changed it around slightly because I am using an EPS file. I can't get it to work with JPGs either, so I can't imagine that is the problem.

When I plug this in and load the tex file I get this:
workingexample.jpg
workingexample.jpg (13.22 KiB) Viewed 5941 times
You can easily see the two problems as compared to the example provided by the people at Code Alias, which I am including below. All the bars are black, and the text is offset from the graph.
histo.jpeg
histo.jpeg (39.75 KiB) Viewed 5929 times
I am using Gnuplot version 4.4 patchlevel 0 for Microsoft Windows. Any help is much appreciated. Thank you,

Jason
Last edited by jason2 on Fri Mar 11, 2011 8:01 pm, edited 1 time in total.

Recommended reading 2024:

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

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

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

Gnuplot: Histogram bars all black & chart offset to axes

Post by localghost »

You are setting the wrong terminal. With respect to the chosen output the first line of the Gnuplot script should look at least like the following.

Code: Select all

set term post eps enhanced color
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The Gnuplot manual has more details about specific terminals and their options. The gnuplottex package makes inclusion of such plots more convenient.

Code: Select all

Code, edit and compile here:
\documentclass{minimal}
\usepackage{gnuplottex}
\begin{document}
\begin{gnuplot}[terminal=post,terminaloptions=eps enhanced color]
set boxwidth 0.75 absolute
set style fill solid 1.00 border -1
set style histogram rowstacked
set style data histograms
set xtics 1000 nomirror
set ytics 100 nomirror
set mxtics 2
set mytics 2
set ytics 10
set yrange [0:40]
set ylabel "Total time"
set xlabel "Session number"
plot 'data.dat' using 3 t "Server", '' using 4 t "Client", '' using 5:xtic(1) t "Network"
\end{gnuplot}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Run this code throught »LaTeX → DVI → PS (→ PDF)«. Pay special attention to remarks in the package manual (keyword: shell escape).
Rendered output of the above given code.
Rendered output of the above given code.
gnuplot-xmpl.png (9.5 KiB) Viewed 5934 times
However, there is a smarter solution by the pgfplots package (based on pgf/tikZ). See code below for a translation of the above Gnuplot script.

Code: Select all

Code, edit and compile here:
\documentclass{minimal}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[%
xlabel={Session number},
ylabel={Total time},
ymin=0,ymax=40,
xtick={1,2,...,10},
ybar stacked,
minor y tick num=1,
legend style={%
at={(0.02,0.98)},
anchor=north west,
area legend
}
]
\addplot table[x index=0,y index=2] {data.dat};
\addplot table[x index=0,y index=3] {data.dat};
\addplot table[x index=0,y index=4] {data.dat};
\legend{Server,Client,Network};
\end{axis}
\end{tikzpicture}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
As above, pay special attention to the package manual (keyword: shell escape). Similar results can be obtained with pst-plot (based on PSTricks).
Rendered output of the above given code.
Rendered output of the above given code.
pgfplots-xmpl.png (8.94 KiB) Viewed 5938 times

Thorsten
jason2
Posts: 10
Joined: Fri Sep 24, 2010 1:47 am

Re: Gnuplot: Histogram bars all black & chart offset to axes

Post by jason2 »

Thanks, I used the latter strategy and it worked great.
Post Reply