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:
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?
Best Answer
You can make it fit in the given space, but then the
x tick label
s aretiny
Code 1
Result 1
But questions remain:
letter paper
?For comparison:
Code 2
...
Result 2
As suggested by Jake, a scatter plot is probably better that a bar plot for this case:
Code 3
Result 3