icaros-usc / pyribs

A bare-bones Python library for quality diversity optimization.
https://pyribs.org
MIT License
208 stars 33 forks source link

Sliding Boundaries Archive Heatmap Boundaries [BUG] #270

Closed LennartPurucker closed 1 year ago

LennartPurucker commented 1 year ago

Description

Heyho,

I am trying to plot a heatmap of a sliding boundaries archive that shows the boundaries. Therefore, I set the parameter boundary_lw to a value large than 0.

The following picture shows the result of the function call (Fig. 1): image

But what I would like to have the following (Fig. 2): image

Steps to Reproduce

The function call I have used is:

from ribs.visualize import sliding_boundaries_archive_heatmap
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(8, 6))
sliding_boundaries_archive_heatmap(archive, boundary_lw=0.5, ax=ax1)
plt.show()

I can not share the archive I am using.

Potential Fix

I found the following solution while looking at the code.

The current implementation of plotting the boundaries is the following:

if boundary_lw > 0.0:
    ax.vlines(x_boundary,
              lower_bounds[0],
              upper_bounds[0],
              color='k',
              linewidth=boundary_lw)
    ax.hlines(y_boundary,
              lower_bounds[1],
              upper_bounds[1],
              color='k',
              linewidth=boundary_lw)

However, to my understanding of the code, we would need to switch the indices. That is, to plot the boundaries correctly, we need the lower and upper bounds of the other dimension. Hence, the code should be:

if boundary_lw > 0.0:
    ax.vlines(x_boundary,
              lower_bounds[1],
              upper_bounds[1],
              color='k',
              linewidth=boundary_lw)
    ax.hlines(y_boundary,
              lower_bounds[0],
              upper_bounds[0],
              color='k',
              linewidth=boundary_lw)

I have used this code to produce Figure 2.

I am not sure if I am just using the code incorrectly or if this is a bug. I would be happy to hear feedback.

btjanaka commented 1 year ago

Hi @LennartPurucker, thank you for reporting this bug! It indeed looks like the boundary lines are being drawn incorrectly. We are addressing this in #280.

LennartPurucker commented 1 year ago

Hi @btjanaka, the pull request looks great, thank you! This solves the bug and my problem. Hence, I am closing the issue.