Skip to content

Commit

Permalink
Merge pull request #202 from SasView/ticket-1220
Browse files Browse the repository at this point in the history
fix 2D log-scale plotting range when data contains zeros and negative values

as agreed at today's meeting
fixes #1220
  • Loading branch information
butlerpd authored Mar 5, 2019
2 parents f58a13a + 75313af commit 0a924c6
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions src/sas/sasgui/plottools/PlotPanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,7 @@ def image(self, data, qx_data, qy_data, xmin, xmax, ymin, ymax,
Render the current data
"""
# TODO: include mask info in plotter
self.data = data
self.qx_data = qx_data
self.qy_data = qy_data
Expand All @@ -1450,37 +1451,26 @@ def image(self, data, qx_data, qy_data, xmin, xmax, ymin, ymax,
output = self._build_matrix()
else:
output = copy.deepcopy(self.data)
# check scale
# rescale data if necessary
if self.scale == 'log_{10}':
try:
if self.zmin_2D <= 0 and len(output[output > 0]) > 0:
zmin_temp = self.zmin_2D
output[output > 0] = np.log10(output[output > 0])
#In log scale Negative values are not correct in general
#output[output<=0] = math.log(np.min(output[output>0]))
elif self.zmin_2D <= 0:
zmin_temp = self.zmin_2D
output[output > 0] = np.zeros(len(output))
output[output <= 0] = -32
else:
zmin_temp = self.zmin_2D
output[output > 0] = np.log10(output[output > 0])
#In log scale Negative values are not correct in general
#output[output<=0] = math.log(np.min(output[output>0]))
except:
#Too many problems in 2D plot with scale
pass

else:
zmin_temp = self.zmin_2D
with np.errstate(all='ignore'):
output = np.log10(output)
index = np.isfinite(output)
if not index.all():
cutoff = (np.min(output[index]) - np.log10(2)
if index.any() else 0.)
output[~index] = cutoff
# TODO: fix handling of zmin_2D/zmax_2D in _onToggleScale
# For now, use default vmin/vmax from data
#vmin, vmax = self.zmin_2D, self.zmax_2D
vmin, vmax = None, None
self.cmap = cmap
if self.dimension != 3:
#Re-adjust colorbar
self.subplot.figure.subplots_adjust(left=0.2, right=.8, bottom=.2)

im = self.subplot.imshow(output, interpolation='nearest',
origin='lower',
vmin=zmin_temp, vmax=self.zmax_2D,
vmin=vmin, vmax=vmax,
cmap=self.cmap,
extent=(self.xmin_2D, self.xmax_2D,
self.ymin_2D, self.ymax_2D))
Expand Down

0 comments on commit 0a924c6

Please sign in to comment.