Skip to content
Snippets Groups Projects
Commit da045343 authored by Alice Brenon's avatar Alice Brenon
Browse files

Expose label-trimming logic as a separate module for reuse

parent 4babdc56
No related branches found
No related tags found
No related merge requests found
import argparse
from GEODE.Store import prepare, tabular
from GEODE.Visualisation.Legend import trim
import matplotlib.pyplot as plot
import pandas
import seaborn
from sklearn.metrics import confusion_matrix
def trim(name, maxSize):
if len(name) > maxSize:
components = name.split(' ')
return components[0] + ' […]'
else:
return name
def trimLabels(labels, maxWidth):
return labels if maxWidth is None else [trim(l, maxWidth) for l in labels]
def heatmap(matrix, filePath, labels, **kwargs):
plot.figure(figsize=(16,13))
ax = seaborn.heatmap(
......@@ -46,7 +37,7 @@ def prepareData(data, labels=None):
def drawConfusionMatrix(data, outputFile, labels=None, maxWidth=None, **kwargs):
truth, answers, labels = prepareData(data, labels=labels)
matrix = confusion_matrix(truth, answers, labels=labels, normalize='true')
heatmap(matrix, outputFile, trimLabels(labels, maxWidth), **kwargs)
heatmap(matrix, outputFile, trim(labels, maxWidth), **kwargs)
def getArgs(arguments):
cli = argparse.ArgumentParser(
......
from GEODE.Visualisation.ConfusionMatrix import drawConfusionMatrix, heatmap
from GEODE.Visualisation.DensityProfile import densityProfile, drawDensityProfile, plotDensity
from GEODE.Visualisation.Legend import trim as legend
......@@ -23,7 +23,7 @@ from GEODE.ENE import eneLabels
from GEODE.Metadata import article, articleKey, paragraph, paragraphKey, \
fromKey, relativePath, toKey, uid
from GEODE.Store import corpus, Directory, SelfContained, tabular, toTSV
from GEODE.Visualisation import densityProfile, heatmap
from GEODE.Visualisation import densityProfile, heatmap, legend
from GEODE.Visualisation.ConfusionMatrix import drawConfusionMatrixCLI
from GEODE.Visualisation.DensityProfile import drawDensityProfileCLI
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment