2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-19 11:38:05 +02:00

added and automated beautification done by jenson_bo

This commit is contained in:
Martin Thoma 2014-08-06 11:18:27 -04:00
parent 0e289dd133
commit 38478cc7e3
4 changed files with 78 additions and 25 deletions

View file

@ -6,4 +6,7 @@ Credits
--------
Thanks to [esdd](http://tex.stackexchange.com/users/43317/esdd) who helped me
to get the LaTeX part work (see [tex.SE answer](http://tex.stackexchange.com/a/194966/5645))
to get the LaTeX part work (see [tex.SE answer](http://tex.stackexchange.com/a/194966/5645))
Thanks to [jenson_bo](http://tex.stackexchange.com/users/17775/jenson-bo) for
making it beautiful!

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 27 KiB

Before After
Before After

View file

@ -1,7 +1,7 @@
\documentclass[margin=10pt]{standalone}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\pgfplotsset{compat=1.3}
\newcommand\clipright[1][white]{
\fill[#1](current axis.south east)rectangle(current axis.north-|current axis.outer east);
@ -9,36 +9,48 @@
\useasboundingbox(current axis.outer south west)rectangle([xshift=.5ex]current axis.outer north-|current axis.east);
}
\definecolor{mycolor}{rgb}{0.02,0.4,0.7}
\begin{document}
\begin{tikzpicture}
\begin{axis}[/tikz/ybar interval,
ybar legend,
xtick align=outside,
\begin{axis}[
ymajorgrids,
xmajorgrids,
grid style={white,thick},
axis on top,
/tikz/ybar interval,
tick align=outside,
ymin=0,
axis x line*=left,
axis line style={draw opacity=0},
tick style={draw=none},
enlarge x limits=false,
grid=major,
height=7cm,
title={All Results},
xlabel={recording time $t$ in ms},
title style={font=\Large},
xlabel={recording time $t$ in s},
ylabel={Number of Recordings},
xtick={0,...,16},
ytick={0,10000,20000,30000,40000},
scaled ticks=false,
yticklabels={ {{yticklabels}} },
xticklabels={ {{xticklabels}} },
width=\textwidth,
xtick=data,
xticklabel style={
inner sep=0pt,
anchor=north east,
rotate=45
label style={font=\large},
ticklabel style={
inner sep=1pt,
font=\small
},
nodes near coords,
every node near coord/.append style={
anchor=mid west,
fill=white,
anchor=mid west,
shift={(3pt,4pt)},
inner sep=0,
font=\footnotesize,
rotate=45},
]
\addplot[blue, fill=blue!40!white] coordinates { {{coordinates}} };
\legend{Time}
\addplot[mycolor!80!white, fill=mycolor, draw=none] coordinates { {{coordinates}} };
\end{axis}
\clipright
\end{tikzpicture}
\end{document}
\end{document}

View file

@ -4,6 +4,7 @@
from __future__ import print_function
import shutil
import fileinput
import math
def main(filename, bins, maximum):
@ -17,7 +18,7 @@ def main(filename, bins, maximum):
numbers = sorted(numbers)
minimum = min(numbers)
bin_counter = [0 for i in range(bins+1)]
borders = []
xticklabels = []
for i, number in enumerate(numbers):
if number >= minimum + (maximum - minimum)/bins*(bins+1):
bin_counter[bins] += 1
@ -32,21 +33,56 @@ def main(filename, bins, maximum):
break
for b in range(bins):
lower = minimum + (maximum - minimum)/bins*b
borders.append(str(lower))
borders.append("\infty")
return bin_counter, borders
xticklabels.append(get_xticklabel(lower))
# Get labels for y-axis
ytickslabels = []
maxylabel = int(10**math.floor(math.log(max(bin_counter), 10)))
ylabelsteps = maxylabel / 10
for i in range(0, maxylabel+1, ylabelsteps):
ytickslabels.append(get_yticklabel(i, True))
xticklabels.append("\infty")
return bin_counter, xticklabels, ytickslabels
def modify_template(bin_counter, borders):
def get_xticklabel(value):
return str(int(value/1000))
def get_yticklabel(value, si_suffix):
if si_suffix:
divide_by, suffix = get_si_suffix(value)
new_value = (value / divide_by)
if int(new_value) == new_value:
return ("%i" % int(new_value)) + suffix
else:
return ("%0.2f" % new_value) + suffix
else:
return str(value)
def get_si_suffix(value):
if value >= 10**3:
return (10**3, "K")
elif value >= 10**6:
return (10**6, "M")
else:
return (1, "")
def modify_template(bin_counter, xticklabels, yticklabels):
shutil.copyfile("histogram-large-1d-dataset.template.tex",
"histogram-large-1d-dataset.tex")
xticklabels = ", ".join(map(lambda n: "$%s$" % n, borders))
xticklabels = ", ".join(map(lambda n: "$%s$" % n, xticklabels))
yticklabels = ", ".join(yticklabels)
coordinates = ""
for i, value in enumerate(bin_counter):
coordinates += "(%i, %i) " % (i, value)
for line in fileinput.input("histogram-large-1d-dataset.tex",
inplace=True):
line = line.replace("{{xticklabels}}", xticklabels)
line = line.replace("{{yticklabels}}", yticklabels)
line = line.replace("{{coordinates}}", coordinates)
print(line, end='')
@ -65,5 +101,7 @@ if __name__ == '__main__':
help=("what is the maximum number "
"that should get binned?"))
args = parser.parse_args()
bin_counter, borders = main(args.filename, args.bins, args.max)
modify_template(bin_counter, borders)
bin_counter, xticklabels, yticklabels = main(args.filename,
args.bins,
args.max)
modify_template(bin_counter, xticklabels, yticklabels)