Commit c070f4ab authored by Josef Brandt's avatar Josef Brandt

Plots from function

parent 3de80ba6
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
import numpy as np
from evaluation import TotalResults
def get_error_vs_frac_plot(totalResults: TotalResults, attributes: list = [], methods: list = []) -> Figure:
assert len(attributes) == len(methods)
fig: Figure = plt.figure()
numRows: int = 1
numCols: int = 1
if len(attributes) == 0:
attributes = methods = [[]]
elif len(attributes) <= 2:
numCols = len(attributes)
else:
numRows = 2
numCols = np.ceil(len(attributes)/numRows)
index = 0
for attrs, meths in zip(attributes, methods):
ax = fig.add_subplot(numRows, numCols, index + 1)
errorPerFraction: dict = totalResults.get_error_vs_fraction_data(attributes=attrs,
methods=meths)
for methodLabel in errorPerFraction.keys():
errorDict: dict = errorPerFraction[methodLabel]
fractions: list = list(errorDict.keys())
errors: list = [errorDict[fraction][0] for fraction in fractions]
stdevs: list = [errorDict[fraction][1] for fraction in fractions]
ax.errorbar(fractions, errors, stdevs, label=methodLabel, marker='s', capsize=5)
title: str = ''
if len(attrs) > 0:
title = ', '.join(attr for attr in attrs)
print('title is', title)
ax.set_title(title, fontSize=15)
ax.set_xscale('log')
ax.set_xlabel('measured fraction', fontsize=12)
ax.set_ylabel('mpCountError (%)', fontsize=12)
ax.set_xlim([0.9 * min(fractions), 1.05])
ax.set_ylim([0, 100])
ax.legend()
index += 1
return fig
# def get_grouped_spectra_plot(groupedSpectra: list, wavenumbers=None) -> matplotlib.figure.Figure:
# if wavenumbers is None:
# wavenumbers = np.arange(len(groupedSpectra[0][0]))
#
# numLabels = len(groupedSpectra)
# numRows = numLabels // 3
# numCols = np.ceil(numLabels / numRows)
# fig: matplotlib.figure.Figure = plt.figure()
#
# for index, specs in enumerate(groupedSpectra):
# ax = fig.add_subplot(numRows, numCols, index + 1)
# for spec in specs:
# ax.plot(wavenumbers, spec)
# ax.set_title(f'{len(specs)} spectra of label {index + 1}')
#
# return fig
\ No newline at end of file
......@@ -143,4 +143,4 @@ if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
subsampling = MainView()
subsampling.show()
ret = app.exec_()
\ No newline at end of file
ret = app.exec_()
import matplotlib.pyplot as plt
# import matplotlib.pyplot as plt
from matplotlib.figure import Figure
import time
from evaluation import TotalResults, SampleResult
from input_output import get_pkls_from_directory, get_attributes_from_foldername, save_results, load_results
from graphs import get_error_vs_frac_plot
"""
IMPORTANT!!!
......@@ -27,43 +29,6 @@ if __name__ == '__main__':
results: TotalResults = load_results('results1.res')
# save_results('results1.res', results)
plt.clf()
errorPerFraction: dict = results.get_error_vs_fraction_data(attributes=['air', 'water'],
methods=['spiral', 'cross'])
plt.subplot(121)
for methodLabel in errorPerFraction.keys():
errorDict: dict = errorPerFraction[methodLabel]
fractions: list = list(errorDict.keys())
errors: list = [errorDict[fraction][0] for fraction in fractions]
stdevs: list = [errorDict[fraction][1] for fraction in fractions]
plt.errorbar(fractions, errors, stdevs, label=methodLabel, marker='s', capsize=5)
plt.title('Air/Water sample', fontSize=15)
plt.xscale('log')
plt.xlabel('measured fraction', fontsize=12)
plt.ylabel('mpCountError (%)', fontsize=12)
plt.xlim([0.9*min(fractions), 1.05])
plt.ylim([0, 100])
plt.legend()
errorPerFraction: dict = results.get_error_vs_fraction_data(attributes=['sediment', 'soil', 'beach', 'slush'],
methods=['spiral', 'cross'])
plt.subplot(122)
for methodLabel in errorPerFraction.keys():
errorDict: dict = errorPerFraction[methodLabel]
fractions: list = list(errorDict.keys())
errors: list = [errorDict[fraction][0] for fraction in fractions]
stdevs: list = [errorDict[fraction][1] for fraction in fractions]
plt.errorbar(fractions, errors, stdevs, label=methodLabel, marker='s', capsize=5)
plt.title('Sediment/Beach/Slush sample', fontSize=15)
plt.xscale('log')
plt.xlabel('measured fraction', fontsize=12)
plt.ylabel('mpCountError (%)', fontsize=12)
plt.xlim([0.9*min(fractions), 1.05])
plt.ylim([0, 100])
plt.legend()
plt.show()
plot: Figure = get_error_vs_frac_plot(results, attributes=[['air', 'water'], ['sediment', 'soil', 'beach', 'slush']],
methods=[['random', 'size']]*2)
plot.show()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment