# Properly squish a pgfplot bar chart

I am trying to make a bar chart with the following lengthy data:

Character   X-Position  Probability
space   1   0.18211
e   2   0.10083
t   3   0.07298
h   4   0.06721
a   5   0.05862
o   6   0.05435
n   7   0.04792
i   8   0.0421
s   9   0.04067
d   10  0.03916
r   11  0.03827
l   12  0.02508
f   13  0.01982
m   14  0.01964
u   15  0.01781
w   16  0.01676
p   17  0.0163
comma   18  0.01394
c   19  0.01391
y   20  0.01309
1   21  0.01165
g   22  0.0111
b   23  0.01075
v   24  0.00551
N   25  0.00544
:   26  0.00537
I   27  0.00493
.   28  0.00491
k   29  0.00488
2   30  0.00423
A   31  0.00395
;   32  0.00357
L   33  0.00304
3   34  0.00246
G   35  0.00166
4   36  0.00163
5   37  0.00143
7   38  0.00138
8   39  0.00128
6   40  0.00122
0   41  0.0011
9   42  0.00102
J   43  0.00072
S   44  0.00059
B   45  0.00058
-   46  0.00052
j   47  0.00047
x   48  0.00046
T   49  0.0004
W   50  0.00038
?   51  0.00037
H   52  0.00029
F   53  0.00028
O   54  0.00027
Y   55  0.00022
M   56  0.0002
R   57  0.00019
C   58  0.00018
q   59  0.00017
!   60  0.00013
E   61  0.00011
Z   62  0.00011
z   63  0.00009
'   64  0.00004
D   65  0.00004
K   66  0.00004
P   67  0.00003
(   68  0.00002
)   69  0.00002
U   70  0.00001


I put that data in a file called "my.dat", and made my Latex file in the same directory:

\documentclass[letterpaper]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
ybar,
xlabel=Character, ylabel=Probability
xtick=data,
xticklabels from table={my.dat}{Character}
]
x=X-Position,
y=Probability
] {my.dat};

\end{axis}
\end{tikzpicture}
\end{document}


The result is awful:

With Excel I know how to make the chart look decent. The letters come out a bit squished, so I stretch the chart:

But notice how it tried on its own to make the bars as thin as possible to fit it all in the chart. How do I make pgfplots try harder to make everything fit?

Alternatively, it would be nice to know if there were a way to make a bar chart wrap itself, as in cut into portions and each displayed next to/on top of the other.

Has anyone who can help had experience with pgfplots trying to graph lots of data?

-
Are you looking for a way to make the bars automatically fit into a plot of a specified width? Or do you just want to know how to specify the bar width? – Jake Sep 18 '12 at 7:33
you could use width=<length> to set the width of the graph, and bar width=<length> to set the width of the bars. For rotating and shrinking the labels, you can use x tick label style={font=\small,align=right,rotate=90}. – Tom Bombadil Sep 18 '12 at 9:39
@Jake- I want a way to squeeze all of the graph into a smaller area. – Nate Glenn Sep 18 '12 at 16:38

You can make it fit in the given space, but then the x tick labels are tiny

## Code 1

\begin{axis}
[   ybar,
xlabel=Character,
ylabel=Probability,
xtick=data,
xticklabels from table={my.dat}{Character},
bar width=2pt,
width=0.95*\textwidth,
x tick label style={font=\tiny,align=right,rotate=90},
enlarge x limits=0.01,
enlarge y limits=0.01,
]
[   x=X-Position,
y=Probability
]
{my.dat};
\end{axis}


## Result 1

But questions remain:

• do you have to do this on letter paper?
• do the margins need to be this big?
• wouldn't a logarhitmic plot be better, as the right side of the diagram is basically empty?

For comparison:

## Code 2

\usepackage[margin=0.6in]{geometry}


...

\begin{semilogyaxis}
ybar,
xlabel=Character,
ylabel=Probability,
xtick=data,
xticklabels from table={my.dat}{Character},
bar width=5pt,
width=0.95*\textwidth,
x tick label style={font=\footnotesize,align=right,rotate=90},
enlarge x limits=0.01,
enlarge y limits=0.01,
]
[   x=X-Position,
y=Probability
]
{my.dat};
\end{semilogyaxis}


## Result 2

As suggested by Jake, a scatter plot is probably better that a bar plot for this case:

## Code 3

\begin{semilogyaxis}
[   scatter,
scatter src=y,
only marks,
xlabel=Character,
ylabel=Probability,
xtick=data,
xticklabels from table={my.dat}{Character},
bar width=5pt,
width=0.95*\textwidth,
x tick label style={font=\footnotesize,align=right,rotate=90},
enlarge x limits=0.01,
enlarge y limits=0.02,
grid=major,
colormap={portal}{rgb255(0cm)=(255,128,0); rgb255(1cm)=(0,255,255)},
colormap name=portal,
]
[   x=X-Position,
y=Probability
]
{my.dat};
\end{semilogyaxis}


## Result 3

-
+1, but logarithmic bar plots are a Bad Idea, since they don't have a natural origin. See bzintelguru.com/blog/… for a nice explanation. – Jake Sep 20 '12 at 15:31
@Jake: In the linked example I agree that it's a bad idea. But tell me, how are you going to read of the values in the first example? By comparing the lengths of the bars? As the given data streches four orders of magnitude, I think a logarithmic plot is justified. – Tom Bombadil Sep 20 '12 at 22:59
A logarithmic plot is indeed justified, but not a logarithmic bar plot. A scatterplot would work better in this case, in my opinion. – Jake Sep 21 '12 at 5:51
@Jake: Okay, that we can agree upon. – Tom Bombadil Sep 21 '12 at 8:32
I'm getting an error: Environment semilogyaxis undefined. Did you have to include anything besides pgfplots? – Nate Glenn Sep 21 '12 at 16:47