Skip to content

[routines/heatmap] Refactor: change how x-ticks are defined

Arin Wongprommoon requested to merge hotfix-issue-024 into master

When the user defines xtick_step and sampling_period so that sampling_period is not divisible by xtick_step, an error is shown. Specifically:

int(np.where(time_axis == label)[0].item()) for label in xticklabels

ValueError: can only convert an array of size 1 to a Python scalar

The routine assumed that all instances of label (line 66) can be found in time_axis (defined in line 61). This is not true when sampling_period is not divisible by xtick_step -- as an example:

Suppose time_axis is: [0, 1, 2, 3, 4, 5, 6, 7] And xtick_step is 0.6. xtick_min is thus defined as 0 and xtick_max is thus defined as 7.2, as expected. xticklabels is then defined as [0, 0.6, 1.2, 1.8, ... 7.2] In the list comprehension that defines self.xticks, label first acquires the value of 0. This results in no errors as time_axis contains a 0. However, when label then acquires the value of 0.6, the ValueError is returned because time_axis does not contain a 0.6.

Fortunately, Axes.xaxis.set_major_locator() does all this for me, so I scrapped the original method of defining horizontal axis for this. I had originally written the lines to define the horizontal axis when I didn't know that set_major_locator() existed, and tried to define the x-ticks manually.

These changes should not affect the behaviour of heatmap apart from cases that cause the error.

This commit fixes issue #19 (closed).

Merge request reports