Compare commits

..

3 commits

Author SHA1 Message Date
5dde85d70e Merge branch 'main' of https://forge.bexus.org/Chaos/BGO
Ich konnte nicht git push, musste erst git pull, aber durfte ich auch nicht, also habe ich merge gemacht mit rebase false.
2024-03-13 14:27:16 +01:00
43d476e5b7 added figure title and ability to only plot certain channels 2024-03-13 14:24:59 +01:00
0a3163359c set y- axis scale to logarithmic 2024-03-13 11:40:52 +01:00

View file

@ -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: