def get1DobjectsSmooth(vals, xPos, xText='x', yPosDelta=0.5, size=0.3, vMax=None, vMin=None, highlight=None): if vMin is None: minVal = min(vals) else: minVal = vMin if vMax is None: maxVal = max(vals) else: maxVal = vMax size1 = 0.2 + 0.8 * (np.array(vals) - minVal) / (maxVal - minVal) colors = plt.cm.Blues(size1)[:, :-1] allObj = [] for i, color in enumerate(colors): if (highlight is not None) and (highlight != i): color = cl.rgb_to_hsv(color) # color[0] = 0 color[1] = 0 color = cl.hsv_to_rgb(color) obj = sO.Cube() obj.source.SetCenter(xPos, i * yPosDelta, 0) obj.setSize(size * size1[i]) obj.setColor(color) if (highlight is not None) and (highlight != i): obj.actor.GetProperty().SetOpacity(0.2) allObj.append(obj) xLabel = sO.Text(f'{xText}') xLabel.actor.SetScale(0.1, 0.1, 0.1) xLabel.actor.SetPosition(xPos - 0.2, -1, 0) xLabel.actor.GetProperty().SetColor(0, 0, 0) allObj.append(xLabel) ax1 = sO.Line((xPos, -0.4, 0), (xPos, -0.6, 0)) allObj.append(ax1) return allObj
def get2DObjects(colors2D, sizes2D, xPos, xText='x', yPosDelta=0.5, zPosDelta=0.5, size=0.3, maxNz=10, highlight=None): allObj = [] for i, (colors, sizes) in enumerate(zip(colors2D, sizes2D)): for j, (c, s) in enumerate(zip(colors, sizes)): if j > maxNz: break if (highlight is not None) and (highlight != i): c = cl.rgb_to_hsv(c) # color[0] = 0 c[1] = 0 c = cl.hsv_to_rgb(c) obj = sO.Cube() obj.source.SetCenter(xPos, i * yPosDelta, -j * zPosDelta) obj.setSize(size * s) obj.setColor(c) if (highlight is not None) and (highlight != i): obj.actor.GetProperty().SetOpacity(0.1) allObj.append(obj) xLabel = sO.Text(f'{xText}') xLabel.actor.SetScale(0.1, 0.1, 0.1) xLabel.actor.SetPosition(xPos - 0.2, -1, 0) xLabel.actor.GetProperty().SetColor(0, 0, 0) allObj.append(xLabel) ax1 = sO.Line((xPos, -0.4, 0), (xPos, -0.6, 0)) allObj.append(ax1) return allObj
def get1Dobjects(colors, xPos, xText='x', yPosDelta=0.5, size=0.3, highlight=None): allObj = [] for i, color in enumerate(colors): if (highlight is not None) and (highlight != i): color = cl.rgb_to_hsv(color) # color[0] = 0 color[1] = 0 color = cl.hsv_to_rgb(color) obj = sO.Cube() obj.source.SetCenter(xPos, i * yPosDelta, 0) obj.setSize(size) obj.setColor(color) if (highlight is not None) and (highlight != i): obj.actor.GetProperty().SetOpacity(0.2) allObj.append(obj) xLabel = sO.Text(f'{xText}') xLabel.actor.SetScale(0.1, 0.1, 0.1) xLabel.actor.SetPosition(xPos - 0.2, -1, 0) xLabel.actor.GetProperty().SetColor(0, 0, 0) allObj.append(xLabel) ax1 = sO.Line((xPos, -0.4, 0), (xPos, -0.6, 0)) allObj.append(ax1) return allObj
def getDiagnObjs(diagn, xPos, xText='x', yPosDelta=0.5, zPosDelta=0.5, size=0.3, highlight=None): uniques = set([]) for ds in diagn: for d in ds: uniques.update(d) uniques = sorted(list(uniques)) nUniq = len(uniques) colors = {m: plt.cm.tab20b(i / nUniq)[:-1] for i, m in enumerate(uniques)} poss = {m: i for i, m in enumerate(uniques)} allObj = [] for i, patient in enumerate(diagn): for j, day in enumerate(patient): for k, disease in enumerate(uniques): if disease in day: c = colors[disease] if (highlight is not None) and (highlight != i): c = cl.rgb_to_hsv(c) c[1] = 0 c = cl.hsv_to_rgb(c) obj = sO.Cube() obj.source.SetCenter(xPos - k * size / (nUniq), i * yPosDelta, -j * zPosDelta) obj.setSize(size / (nUniq + 1)) obj.setColor(c) if (highlight is not None) and (highlight != i): obj.actor.GetProperty().SetOpacity(0.1) allObj.append(obj) for i, u in enumerate(uniques): xTick = sO.Line((xPos - i * size / (nUniq), -0.4, 0), (xPos - i * size / (nUniq), -0.6, 0)) allObj.append(xTick) xLabel = sO.Text(f'[{xText}]-{u}') xLabel.actor.SetScale(0.1, 0.1, 0.1) xLabel.actor.SetPosition(xPos - i * size / (nUniq), -1, 0) xLabel.actor.GetProperty().SetColor(0, 0, 0) xLabel.actor.RotateZ(-90) allObj.append(xLabel) xLabel = sO.Text(f'{xText}') xLabel.actor.SetScale(0.1, 0.1, 0.1) xLabel.actor.SetPosition(xPos - 0.6, -0.8, 0) xLabel.actor.GetProperty().SetColor(0, 0, 0) allObj.append(xLabel) ax = sO.Line((xPos, -0.5, 0), (xPos - (nUniq - 1) * size / (nUniq), -0.5, 0)) allObj.append(ax) return allObj
def plot2D(config): bgColor = [217 / 255, 211 / 255, 232 / 255] # bgColor = [219/255, 225/255, 235/255] Npatients = 10 data = getData()[:Npatients + 1] header = data[0] data = data[1:] site, patient, sex, race = zip(*data) N = len(site) ren.SetBackground(bgColor) renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) sexColors = colorMapper(sex) raceColors = colorMapper(race) siteColors = colorMapper(site) if config['ohe']: for m in listToBin(sex, posDelta=0.4, startPos=4, startStr='sex'): ren.AddActor(m.actor) for m in listToBin(race, posDelta=0.4, startPos=5, startStr='race'): ren.AddActor(m.actor) # Render the x-axes ax1 = sO.Line((1, -0.5, 0), (3, -0.5, 0)) ren.AddActor(ax1.actor) for i in range(3): ax1 = sO.Line((i + 1, -0.4, 0), (i + 1, -0.6, 0)) ren.AddActor(ax1.actor) # Render the y-axes ax1 = sO.Line((0, 0, 0), (0, (Npatients - 1) * 0.5, 0)) ren.AddActor(ax1.actor) for i in range(Npatients): ax1 = sO.Line((-0.1, i * 0.5, 0), (0.1, i * 0.5, 0)) ren.AddActor(ax1.actor) for patient in range(Npatients): # Set the names for the patients myText = sO.Text(f'p_{patient:04d}') myText.actor.SetScale(0.1, 0.1, 0.1) myText.actor.SetPosition(-1, patient * 0.5, 0) myText.actor.GetProperty().SetColor(0, 0, 0) ren.AddActor(myText.actor) # set the cohort values cohort = sO.Sphere() cohort.actor.SetScale(0.3) cohort.actor.SetPosition(1, patient * 0.5, 0) cohort.setColor((0, 1, 0)) ren.AddActor(cohort.actor) # set the sex values sex = sO.Cube() sex.source.SetCenter(2, patient * 0.5, 0) sex.setSize(0.3) sex.setColor(sexColors[patient]) ren.AddActor(sex.actor) # set the race values race = sO.Cube() race.source.SetCenter(3, patient * 0.5, 0) race.setSize(0.3) race.setColor(raceColors[patient]) ren.AddActor(race.actor) # Set the names for the axes for pos, dataType in enumerate(['cohort', 'sex ', 'race']): myText = sO.Text(f'{dataType}') myText.actor.SetScale(0.1, 0.1, 0.1) myText.actor.SetPosition(pos + 0.8, -1, 0) myText.actor.GetProperty().SetColor(0, 0, 0) ren.AddActor(myText.actor) renWin.SetSize(900, 900) renWin.SetWindowName('Cylinder') iren.AddObserver("KeyPressEvent", Keypress) iren.Initialize() ren.ResetCamera() restoreCammeraSpecs('../results/cameraPos/latest2D.json') renWin.Render() # Start the event loop. iren.Start() return