autoscale works now also correctly in logarithmic plots (Fixes #8)
This commit is contained in:
+32
-10
@@ -2959,6 +2959,7 @@ class MonitorWidgets:
|
|||||||
if self.__rescale:
|
if self.__rescale:
|
||||||
x_scale = self.display_x_scaling_combobox.get_active_text( )
|
x_scale = self.display_x_scaling_combobox.get_active_text( )
|
||||||
y_scale = self.display_y_scaling_combobox.get_active_text( )
|
y_scale = self.display_y_scaling_combobox.get_active_text( )
|
||||||
|
# x-axis
|
||||||
if x_scale == "lin":
|
if x_scale == "lin":
|
||||||
self.matplot_axes.set_xscale( "linear" )
|
self.matplot_axes.set_xscale( "linear" )
|
||||||
self.matplot_axes.set_xlim(xmin, xmax)
|
self.matplot_axes.set_xlim(xmin, xmax)
|
||||||
@@ -2971,7 +2972,7 @@ class MonitorWidgets:
|
|||||||
#self.display_autoscaling_checkbutton.set_active(True) #partial fix T141
|
#self.display_autoscaling_checkbutton.set_active(True) #partial fix T141
|
||||||
self.matplot_axes.set_xlim(xmax, xmin)
|
self.matplot_axes.set_xlim(xmax, xmin)
|
||||||
#self.matplot_axes.invert_xaxis()
|
#self.matplot_axes.invert_xaxis()
|
||||||
|
# y-axis
|
||||||
if y_scale == "lin":
|
if y_scale == "lin":
|
||||||
self.matplot_axes.set_yscale( "linear" )
|
self.matplot_axes.set_yscale( "linear" )
|
||||||
self.matplot_axes.set_ylim(ymin, ymax)
|
self.matplot_axes.set_ylim(ymin, ymax)
|
||||||
@@ -2981,18 +2982,39 @@ class MonitorWidgets:
|
|||||||
self.__rescale = False
|
self.__rescale = False
|
||||||
|
|
||||||
# Autoscaling activated?
|
# Autoscaling activated?
|
||||||
elif self.display_autoscaling_checkbutton.get_active( ):
|
elif self.display_autoscaling_checkbutton.get_active():
|
||||||
|
|
||||||
xlim_min, xlim_max = self.matplot_axes.get_xlim( )
|
xlim_min, xlim_max = self.matplot_axes.get_xlim()
|
||||||
if xlim_min != xmin or xlim_max != xmax:
|
if xlim_min != xmin or xlim_max != xmax:
|
||||||
self.matplot_axes.set_xlim( xmin, xmax )
|
self.matplot_axes.set_xlim(xmin, xmax)
|
||||||
|
|
||||||
# Rescale if new max is much larger than old ymax, simialar rules apply to ymin
|
ylim_min, ylim_max = self.matplot_axes.get_ylim()
|
||||||
ylim_min, ylim_max = self.matplot_axes.get_ylim( )
|
|
||||||
ydiff = ymax - ymin
|
# Check if y-axis is log scale
|
||||||
if (ylim_max < ymax or ylim_min > ymin or
|
yscale = self.matplot_axes.get_yscale()
|
||||||
ylim_max > ymax + 0.2 * ydiff or ylim_min < ymin - 0.2 * ydiff):
|
|
||||||
self.matplot_axes.set_ylim( ymin, ymax )
|
if yscale == 'log' or yscale == 'symlog':
|
||||||
|
# For log scales, work with log values to avoid issues with
|
||||||
|
# small numbers (undetected rescale)
|
||||||
|
# Use log-space calculations
|
||||||
|
log_ymin, log_ymax = numpy.log10(ymin), numpy.log10(ymax)
|
||||||
|
|
||||||
|
log_diff = log_ymax - log_ymin
|
||||||
|
|
||||||
|
# Add a small margin in log space (about 0.08 in log10 units ~20% margin)
|
||||||
|
new_ymin = 10**(log_ymin - 0.08 * max(log_diff, 1))
|
||||||
|
new_ymax = 10**(log_ymax + 0.08 * max(log_diff, 1))
|
||||||
|
|
||||||
|
# Only update if values would change significantly
|
||||||
|
if (ylim_max < ymax or ylim_min > ymin or
|
||||||
|
ylim_max > new_ymax * 1.2 or ylim_min < new_ymin / 1.2):
|
||||||
|
self.matplot_axes.set_ylim(new_ymin, new_ymax)
|
||||||
|
else:
|
||||||
|
# Original linear scale logic
|
||||||
|
ydiff = ymax - ymin
|
||||||
|
if (ylim_max < ymax or ylim_min > ymin or
|
||||||
|
ylim_max > ymax + 0.2 * ydiff or ylim_min < ymin - 0.2 * ydiff):
|
||||||
|
self.matplot_axes.set_ylim(ymin, ymax)
|
||||||
|
|
||||||
xdata = in_result.get_xdata( )
|
xdata = in_result.get_xdata( )
|
||||||
chans = in_result.get_number_of_channels( )
|
chans = in_result.get_number_of_channels( )
|
||||||
|
|||||||
Reference in New Issue
Block a user