Skip to content

TST: adapt colorbar tests to changes in matplotlib master #1962

Closed

Description

@martinfleis

Matplotlib made a major overhaul of their colorbar machinery in matplotlib/matplotlib#20054. As a consequence, some of our tests are now failing (see https://github.com/geopandas/geopandas/runs/2731536698?check_suite_focus=true#step:6:2974).

From what I understand, we need to fix our tests, not the implementation but I haven't dig deep into that.

Activity

  1. martinfleis commented on Jul 5, 2021

    @martinfleis
    MemberAuthor

    Colorbars are now plotted differently, there is no collection on their axis anymore, causing this line (and same below) to fail on IndexError: list index out of range

    cbar_colors = _get_colorbar_ax(ax.get_figure()).collections[-1].get_facecolors()

    I don't know how to get those colors anymore.

    The second failure here

    assert cax.get_ylabel() == label_txt
    is caused by reorganization of axes. So the label is now accessible as cax.child_axes[0].get_ylabel() instead of cax.get_ylabel(). Similarly, line 746 now needs to be cax.child_axes[0].get_xlabel().

    The last failure is caused by the fact that the colorbar axis does not have the label passed in divider.append_axes, hence has no name. Can be rewritten using

    plot_height = fig.axes[0].get_position().height
    legend_height =  fig.axes[1].get_position().height

    plot_height = _get_ax(fig, "").get_position().height
    legend_height = _get_ax(fig, "fixed_colorbar").get_position().height

    I can fix the second and third issues now, I'd appreciate help with the first one if there's someone more familiar with matplotlib internals.

  2. self-assigned this
    on Jul 5, 2021
  3. added this to the 0.10 milestone on Jul 5, 2021
  4. TLouf commented on Jul 7, 2021

    @TLouf
    Contributor

    I don't know how to get those colors anymore.

    The breaking change from matplotlib is that the axis we get from _get_colorbar_ax, the one with label "<colorbar>", is no longer the one directly containing the pcolormesh. This is now drawn in a inset axis of the latter. To fix the test, _get_colorbar_ax should return this inset axis, by looking in the children of the currently returned axis for an axis with label "inset_axes". I made a quick test and it seems to work.

    Edit: well actually I now realize you had the solution in the remainder of your message, taking .child_axes[0], of which I ignored the existence, is simpler.

  5. martinfleis commented on Jul 7, 2021

    @martinfleis
    MemberAuthor

    @TLouf would you like to turn it into a PR?

  6. TLouf commented on Jul 7, 2021

    @TLouf
    Contributor

    Yes no problem, I'm on it.

  7. Zeroto521 commented on Jul 8, 2021

    @Zeroto521
    Contributor

    Guys.
    After matplotlib/matplotlib#20501 was merged, CI got fail again.

    There were some new changes to the colorbar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions