mirror of
https://github.com/MartinThoma/LaTeX-examples.git
synced 2025-04-26 06:48:04 +02:00
added parameter for number of yticks
This commit is contained in:
parent
38478cc7e3
commit
46b70eaba2
1 changed files with 25 additions and 12 deletions
|
@ -7,7 +7,7 @@ import fileinput
|
|||
import math
|
||||
|
||||
|
||||
def main(filename, bins, maximum):
|
||||
def main(filename, bins, maximum, yticks):
|
||||
with open(filename) as f:
|
||||
content = f.read().split("\n")
|
||||
numbers = []
|
||||
|
@ -36,21 +36,27 @@ def main(filename, bins, maximum):
|
|||
xticklabels.append(get_xticklabel(lower))
|
||||
|
||||
# Get labels for y-axis
|
||||
yticks = []
|
||||
ytickslabels = []
|
||||
maxylabel = int(10**math.floor(math.log(max(bin_counter), 10)))
|
||||
ylabelsteps = maxylabel / 10
|
||||
maxy = max(bin_counter)
|
||||
maxylabel = int(10**math.floor(math.log(maxy, 10)))*int(str(maxy)[0])
|
||||
ylabelsteps = maxylabel / yticks
|
||||
for i in range(0, maxylabel+1, ylabelsteps):
|
||||
print("i: %i, %i" % (i, maxylabel))
|
||||
print("label: %i%s" % get_si_suffix(i))
|
||||
yticks.append(str(i))
|
||||
ytickslabels.append(get_yticklabel(i, True))
|
||||
|
||||
xticklabels.append("\infty")
|
||||
return bin_counter, xticklabels, ytickslabels
|
||||
return bin_counter, xticklabels, ytickslabels, yticks
|
||||
|
||||
|
||||
def get_xticklabel(value):
|
||||
return str(int(value/1000))
|
||||
return str(int(value))
|
||||
|
||||
|
||||
def get_yticklabel(value, si_suffix):
|
||||
value = float(value)
|
||||
if si_suffix:
|
||||
divide_by, suffix = get_si_suffix(value)
|
||||
new_value = (value / divide_by)
|
||||
|
@ -71,11 +77,12 @@ def get_si_suffix(value):
|
|||
return (1, "")
|
||||
|
||||
|
||||
def modify_template(bin_counter, xticklabels, yticklabels):
|
||||
def modify_template(bin_counter, xticklabels, yticklabels, yticks):
|
||||
shutil.copyfile("histogram-large-1d-dataset.template.tex",
|
||||
"histogram-large-1d-dataset.tex")
|
||||
xticklabels = ", ".join(map(lambda n: "$%s$" % n, xticklabels))
|
||||
yticklabels = ", ".join(yticklabels)
|
||||
yticks = ",".join(yticks)
|
||||
coordinates = ""
|
||||
for i, value in enumerate(bin_counter):
|
||||
coordinates += "(%i, %i) " % (i, value)
|
||||
|
@ -83,13 +90,15 @@ def modify_template(bin_counter, xticklabels, yticklabels):
|
|||
inplace=True):
|
||||
line = line.replace("{{xticklabels}}", xticklabels)
|
||||
line = line.replace("{{yticklabels}}", yticklabels)
|
||||
line = line.replace("{{yticks}}", yticks)
|
||||
line = line.replace("{{coordinates}}", coordinates)
|
||||
print(line, end='')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from argparse import ArgumentParser
|
||||
parser = ArgumentParser()
|
||||
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
|
||||
parser = ArgumentParser(description=__doc__,
|
||||
formatter_class=ArgumentDefaultsHelpFormatter)
|
||||
parser.add_argument("-f", "--file", dest="filename",
|
||||
default="1ddata.txt",
|
||||
help="use FILE as input data", metavar="FILE")
|
||||
|
@ -100,8 +109,12 @@ if __name__ == '__main__':
|
|||
default=15000,
|
||||
help=("what is the maximum number "
|
||||
"that should get binned?"))
|
||||
parser.add_argument("--yticks", dest="yticks", type=int,
|
||||
default=5,
|
||||
help=("How many y-ticks should be used?"))
|
||||
args = parser.parse_args()
|
||||
bin_counter, xticklabels, yticklabels = main(args.filename,
|
||||
args.bins,
|
||||
args.max)
|
||||
modify_template(bin_counter, xticklabels, yticklabels)
|
||||
bin_counter, xticklabels, yticklabels, yticks = main(args.filename,
|
||||
args.bins,
|
||||
args.max,
|
||||
args.yticks)
|
||||
modify_template(bin_counter, xticklabels, yticklabels, yticks)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue