Skip to content

Commit

Permalink
Merge pull request #31 from JKThanassi/normalizing_option
Browse files Browse the repository at this point in the history
After checking things through after getting some time it works.
  • Loading branch information
cduff4464 authored Oct 3, 2016
2 parents 624b7d2 + c567762 commit fecb1ed
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 17 deletions.
26 changes: 18 additions & 8 deletions xpdView/waterfall_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __init__(self, key_list, data_dict, fig, canvas):
self.data_dict = data_dict
self.key_list = key_list
self.fig = fig
self.normalized = False
self.canvas = canvas
self.ax = self.fig.add_subplot(111)
self.x_offset = 0
Expand All @@ -50,16 +51,25 @@ def generate_waterfall(self):
None
"""
self.ax.cla()
# self.ax.hold(True)
for i in range(0, len(self.key_list)):
temp_x = self.normalized_data[self.key_list[i]][0].copy()
temp_y = self.normalized_data[self.key_list[i]][1].copy()
temp_x += self.x_offset * i
temp_y += self.y_offset * i
self.ax.plot(temp_x, temp_y)
title = 'Data not normalized'
if self.normalized:
data = self.normalized_data
title = 'Data Normalized'
else:
data = self.data_dict
list_data = (data[k] for k in self.key_list) # you can do a list comp here too
for i, (x, y) in enumerate(list_data):
self.ax.plot(x + self.x_offset * i, y + self.y_offset * i)
self.ax.set_title(title)
self.ax.autoscale()
self.canvas.draw()

def is_normalized(self):
return self.normalized

def set_normalized(self, state):
self.normalized = state

def normalize_data(self):
"""This method normalizes data for plotting
Expand All @@ -72,4 +82,4 @@ def normalize_data(self):
temp = self.data_dict[key].copy()
temp[1] = temp[1] - temp[1].min()
temp[1] = temp[1] / (temp[1].max() - temp[1].min())
self.normalized_data[key] = temp
self.normalized_data[key] = temp
26 changes: 17 additions & 9 deletions xpdView/xpd_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,21 +603,29 @@ def twod_plot_settings(self):
x_offset_slider.setMinimum(0)
x_offset_slider.setMaximum(20)
x_offset_slider.valueChanged.connect(self.set_x_offset)

normalize_option_label = QtGui.QLabel()
normalize_option_label.setText("Normalize data:")
normalize_option_box = QtGui.QCheckBox()
# data is normalized by default
normalize_option_box.setChecked(self.water.is_normalized())
normalize_option_box.stateChanged.connect(self.set_normalization)
layout = QtGui.QHBoxLayout()
layout.addStretch()
layout.addWidget(y_offset_label)
layout.addStretch()
layout.addWidget(y_offset_slider)
layout.addStretch()
layout.addWidget(x_offset_label)
layout.addStretch()
layout.addWidget(x_offset_slider)
for widget in [y_offset_label, y_offset_slider, x_offset_label, x_offset_slider, normalize_option_label, normalize_option_box]:
layout.addStretch()
layout.addWidget(widget)

settings_window.setLayout(layout)
settings_window.show()
settings_window.exec_()

def set_normalization(self, state):
if state == 2:
self.water.set_normalized(True)
else:
self.water.set_normalized(False)

self.water.generate_waterfall()

def set_x_offset(self, value):
self.water.x_offset = value
self.water.generate_waterfall()
Expand Down

0 comments on commit fecb1ed

Please sign in to comment.