Fix doubling labels in DateAxisItem#2413
Conversation
* Due to floating point errors, comparison for equality sometimes fails to detect doubling values. Use approximative comparison instead. Code is copied from AxisItem.tickValues().
|
Hi @bbc131 Thanks so much for your work on DateAxisItem, it's one of the relatively newer parts of the library, and clearly has some rough corners. I appreciate your work on improving it. Slight nitpick suggestion, no need to cast to An alternative would be to have |
|
A numpy broadcasted version: ticks = np.array(ticks)
close = np.any(np.isclose(allTicks, ticks[:, np.newaxis], rtol=0, atol=minSpc*0.01), axis=-1)
ticks = ticks[~close].tolist() |
* Now, it's more like in AxisItem.tickValues()
* Use `numpy.isclose()` instead of `filter()` with lambda
| valueSpecs.append((spec.spacing, tick_list)) | ||
| # we assume here that if the difference between a tick value and a previously seen tick value | ||
| # is less than min-spacing/100, then they are 'equal' and we can ignore the new tick. | ||
| ticks = np.array(ticks) |
There was a problem hiding this comment.
I suppose this line is redundant since ticks is already an ndarray, something that wasn't obvious to me at the time.
There was a problem hiding this comment.
You're right, I updated it.
* `ticks` is already a `numpy.ndarray`
| ) | ||
| ticks = ticks[~close] | ||
| allTicks = np.concatenate([allTicks, ticks]) | ||
| valueSpecs.append((spec.spacing, ticks)) |
There was a problem hiding this comment.
To respect the description in the method docstring, ticks would need to be converted to a Python list here.
i.e.
valueSpecs.append((spec.spacing, ticks.tolist()))
pyqtgraph/graphicsItems/AxisItem.py
Outdated
| ) | ||
| values = values[~close] | ||
| allValues = np.concatenate([allValues, values]) | ||
| ticks.append((spacing/self.scale, values)) |
There was a problem hiding this comment.
To respect the description in the method docstring, values would need to be converted to a Python list here.
i.e.
ticks.append((spacing/self.scale, values.tolist())There was a problem hiding this comment.
Thanks for being so attentive. I see, you had this correct already in your very first comment, but I removed it silently ;)
In short
In detail
In some situations
DateAxisItemdraws two different tick labels (of different levels) for the same value. See the following screenshot, where "60.0" and "02:01:00" are drawn. "60.0" should be skipped and only "02:01:00" should be drawn.This can be reproduced, using the
DateAxisItemexample, simply zoom in like in the screenshot. There, the visible range is something between 0.01s and 0.004s. It seems to happen at each full minute. Note, that the occurence depends also on the minimum axis value, meaning it may be necessary to pan the axis a bit to the left or right always keeping the full minute within the visible range.