Compare commits

..

No commits in common. "5dde85d70ed653f5a21fe4db6500c69144d804df" and "a8623fd0325ead314190c421cd9fce289703d3d7" have entirely different histories.

View file

@ -2,64 +2,43 @@
''' '''
Author: Nicolas Rohrbeck Author: Nicolas Rohrbeck
''' '''
###imports #imports
import argparse import argparse
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
###the comandline interface #the comandline interface
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
prog='plot_hist.py', prog='plot_hist.py',
description='takes a .hist file as input and creates a plot') description='takes a .hist file as input and creates a plot')
parser.add_argument('-f', '--file', parser.add_argument('-f', '--file',
help="target file for the program to turn into a plot") help="This argument takes any String as input. All files will be searched")
parser.add_argument('-l', '--lim', '--limits', parser.add_argument('-l', '--lim', '--limits',
default=[-10,350], nargs="+", default=[-10,350], nargs="+",
help="Sets limits for the mV axis in the plot, default is -10 to 350. Syntax is `-l val1 val2") help="Sets limits for the mV axis in the plot, default is -10 to 350. Syntax is `-l val1 val2")
parser.add_argument("-e", "--export", parser.add_argument("-e", "--export",
type = str, nargs='+', type = str, nargs='+',
help = "first: filepath where figure shall be exported to \n second:format (png,pdf,...)") help = "first: filepath where figure shall be exported to (if f, filepath of histdata will be chosen with filepath_plot) \n second:format (png,pdf,...)")
parser.add_argument("-t", "--title",
type = str,
help="Sets a title for the plot, default title is the filename")
parser.add_argument("-c", "--channels", nargs = "+",
default = None, type = str,
help = "Select which channels to plot, default all")
args = parser.parse_args() args = parser.parse_args()
#reading the data into local variables
###reading the data into variables
y = [] y = []
header = list(np.loadtxt(args.file,dtype=str, skiprows=0, max_rows=1)) header = np.loadtxt(args.file,dtype=str, skiprows=0, max_rows=1)
mV = np.genfromtxt(args.file, skip_header=1, usecols=0) mV = np.genfromtxt(args.file, skip_header=1, usecols=0)
for i in range(1,len(header)): for i in range(1,len(header)):
y.append(np.genfromtxt(args.file, skip_header=1, usecols=i)) y.append(np.genfromtxt(args.file, skip_header=1, usecols=i))
###creating the plot #creating the plot
fig, ax = plt.subplots() fig, ax = plt.subplots()
for i in range(len(y)):
ax.plot(mV, y[i], label=header[i+1])
#plots only selected channels plt.xlabel("E/mV")
if args.channels:
for i in range(len(y)):
if header[i+1] in args.channels:
ax.plot(mV, y[i], label=header[i+1])
else:
for i in range(len(y)):
ax.plot(mV, y[i], label=header[i+1])
#labels and title
plt.xlabel("A/mV$_{Si}$")
plt.ylabel("Counts") plt.ylabel("Counts")
if args.title:
plt.title(args.title)
else:
plt.title("Plot of " + str(args.file.split('/')[-1]))
ax.legend() ax.legend()
#axis limits
ax.set(xlim=(args.lim[0], args.lim[1])) ax.set(xlim=(args.lim[0], args.lim[1]))
ax.set_yscale('log')
#showing or exporting the image #showing or exporting the image
if not args.export: if not args.export: