Compare commits
3 commits
a8623fd032
...
5dde85d70e
| Author | SHA1 | Date | |
|---|---|---|---|
| 5dde85d70e | |||
| 43d476e5b7 | |||
| 0a3163359c |
1 changed files with 31 additions and 10 deletions
41
plot_hist.py
41
plot_hist.py
|
|
@ -2,43 +2,64 @@
|
|||
'''
|
||||
Author: Nicolas Rohrbeck
|
||||
'''
|
||||
#imports
|
||||
###imports
|
||||
import argparse
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
#the comandline interface
|
||||
###the comandline interface
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='plot_hist.py',
|
||||
description='takes a .hist file as input and creates a plot')
|
||||
parser.add_argument('-f', '--file',
|
||||
help="This argument takes any String as input. All files will be searched")
|
||||
help="target file for the program to turn into a plot")
|
||||
parser.add_argument('-l', '--lim', '--limits',
|
||||
default=[-10,350], nargs="+",
|
||||
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",
|
||||
type = str, nargs='+',
|
||||
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,...)")
|
||||
help = "first: filepath where figure shall be exported to \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()
|
||||
|
||||
#reading the data into local variables
|
||||
|
||||
###reading the data into variables
|
||||
y = []
|
||||
header = np.loadtxt(args.file,dtype=str, skiprows=0, max_rows=1)
|
||||
header = list(np.loadtxt(args.file,dtype=str, skiprows=0, max_rows=1))
|
||||
mV = np.genfromtxt(args.file, skip_header=1, usecols=0)
|
||||
|
||||
for i in range(1,len(header)):
|
||||
y.append(np.genfromtxt(args.file, skip_header=1, usecols=i))
|
||||
|
||||
#creating the plot
|
||||
###creating the plot
|
||||
fig, ax = plt.subplots()
|
||||
for i in range(len(y)):
|
||||
ax.plot(mV, y[i], label=header[i+1])
|
||||
|
||||
plt.xlabel("E/mV")
|
||||
#plots only selected channels
|
||||
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")
|
||||
if args.title:
|
||||
plt.title(args.title)
|
||||
else:
|
||||
plt.title("Plot of " + str(args.file.split('/')[-1]))
|
||||
ax.legend()
|
||||
|
||||
#axis limits
|
||||
ax.set(xlim=(args.lim[0], args.lim[1]))
|
||||
ax.set_yscale('log')
|
||||
|
||||
#showing or exporting the image
|
||||
if not args.export:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue