[Tex/LaTex] Properly squish a pgfplot bar chart

bar chartpgfplots

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}
]
\addplot table [
    x=X-Position,
    y=Probability
] {my.dat};

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

The result is awful:

enter image description here

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

enter image description here

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?

Best Answer

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,
]
\addplot table
[   x=X-Position,
  y=Probability
] 
{my.dat};
\end{axis}

Result 1

enter image description here


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,
]
\addplot table
[   x=X-Position,
  y=Probability
] 
{my.dat};
\end{semilogyaxis}

Result 2

enter image description here


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,
]
\addplot table
[   x=X-Position,
  y=Probability
] 
{my.dat};
\end{semilogyaxis}

Result 3

enter image description here