Commit 66bba3ab authored by Christian Schneider's avatar Christian Schneider
Browse files

Rename z axis for plotting automatically

parent 42006713
......@@ -90,7 +90,7 @@ class data_grid(data_module_base):
def z(self):
"""Default for two dim grid: Return values"""
return np.array(self.df.values)[self.x_min:self.x_max,
self.y_min:self.y_max]
self.y_min:self.y_max]
@z.setter
def z(self, values):
......@@ -99,7 +99,7 @@ class data_grid(data_module_base):
@property
def values(self):
return np.array(self.df.values)[self.x_min:self.x_max,
self.y_min:self.y_max]
self.y_min:self.y_max]
@values.setter
def values(self, values):
......@@ -231,7 +231,7 @@ class data_grid(data_module_base):
# Plotting #################################################################
def plot(self, name_x=None, name_y=None, cmap='magma', height=400,
width=800, z_min=None, z_max=None):
width=800, z_min=None, z_max=None):
"""Plot table with Holoviews
Parameters
......@@ -246,10 +246,10 @@ class data_grid(data_module_base):
Height of plot in pixels
width : int
Width of plot in pixels
x_min : None, float(Optional)
z_min : None, float(Optional)
Minimum value for z values. If you set this, the scale will not
automatically updated to full contrast.
x_max : None, float (Optional)
z_max : None, float (Optional)
Maximum value for z values
"""
if name_x is None:
......@@ -262,13 +262,15 @@ class data_grid(data_module_base):
else:
y_vals = name_y
hv.opts({'QuadMesh': {'plot': {'width': width, 'height': height},
'style': {'cmap': cmap}}})
ds = hv.Dataset(self.df[self.x_min:self.x_max, self.y_min:self.y_max])
'style': {'cmap': cmap}}})
# Rename z values (to prevent bug in holoviews)
df = self.df[self.x_min:self.x_max, self.y_min:self.y_max].rename('z')
# Create dataset
ds = hv.Dataset(df)
# Create HoloObject
holo_object = hd.regrid(ds.to(hv.QuadMesh, [x_vals, y_vals]))
# Rescale
holo_object = holo_object.redim.range(**{self.name_v:(z_min, z_max)})
holo_object = holo_object.redim.range(**{self.name_v: (z_min, z_max)})
return holo_object
def pcolormesh(self):
......@@ -318,13 +320,13 @@ class data_grid(data_module_base):
cax = divider.append_axes("right", size="5%", pad=0.05)
cbar = plt.colorbar(im, cax=cax)
if zlabel_pos == "top":
cbar.set_label(self.name_v, labelpad=labelpad-32, y=cbar_y+0.58,
cbar.set_label(self.name_v, labelpad=labelpad - 32, y=cbar_y + 0.58,
rotation=0)
elif zlabel_pos == "right":
cbar.set_label(self.name_v, labelpad=labelpad+5, y=cbar_y,
cbar.set_label(self.name_v, labelpad=labelpad + 5, y=cbar_y,
rotation=90)
else:
cbar.set_label(self.name_v, labelpad=labelpad+15, y=cbar_y,
cbar.set_label(self.name_v, labelpad=labelpad + 15, y=cbar_y,
rotation=-90)
return ax
......@@ -540,14 +542,13 @@ class data_grid(data_module_base):
tmp = np.zeros_like(self.y)
err_bars = []
# Guess initial parameters, if none is given
if p0 is None:
tmp_data = data_table([self.x, self.values[:, 0]])
idx_min = np.argmin(tmp_data.y)
offset = np.mean(tmp_data.y)
center = tmp_data.x[idx_min]
width = center/1e6 # kHz as guess
width = center / 1e6 # kHz as guess
amplitude = tmp_data.y[idx_min] - offset
p0 = [center, width, offset, amplitude]
......@@ -574,8 +575,10 @@ class data_grid(data_module_base):
plot_params=False,
maxfev=10000)
tmp[i] = lorentzian_fit(fpars[0], *fpars)
tmp_err_bar = np.sqrt((2*fpars[3]/(np.pi*fpars[1]**2)*fpars_err[1])**2 + fpars_err[2]**2 +
(2/(np.pi*fpars[1])*fpars_err[3])**2)
tmp_err_bar = np.sqrt((2 * fpars[3] / (np.pi * fpars[1] ** 2) *
fpars_err[1]) ** 2 + fpars_err[2] ** 2 +
(2 / (np.pi * fpars[1]) * fpars_err[
3]) ** 2)
err_bars.append(tmp_err_bar)
tmp_name = self.name_v
if adapt_p0:
......@@ -625,7 +628,7 @@ class data_grid(data_module_base):
Qc = 1e4 # Medium value
Qi = 1e4 # Medium value
f0 = tmp_data.x[idx_min] # Frequency of minimum
df = f0/1e6 # MHz?
df = f0 / 1e6 # MHz?
p0 = [offset, Qc, df, f0, Qi]
# Go through y values and find x coordinate for minimum z value
......
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