Skip to content

Error in contourf for matplotlib version 3.10 #14

Closed

Description

@austin-hoover

WIth matplotlib==3.10 (ultraplot==0.99.3), ax.contourf throws an error:

import numpy as np
import ultraplot as uplt

rng = np.random.default_rng(0)
x = rng.normal(size=(1000, 2))
values, edges = np.histogramdd(x, bins=25)

fig, ax = uplt.subplots()
ax.contourf(edges[0], edges[1], values.T)
Traceback (most recent call last):
  File "/Users/46h/repo/ultraplot/tests/test_contourf.py", line 9, in <module>
    ax.contourf(values.T)
  File "/Users/46h/repo/ultraplot/ultraplot/internals/inputs.py", line 327, in _preprocess_or_redirect
    return func(self, *args, **kwargs)  # call unbound method
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/46h/repo/ultraplot/ultraplot/axes/plot.py", line 4224, in contourf
    self._fix_patch_edges(m, **edgefix_kw, **contour_kw)  # no-op if not contour_kw
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/46h/repo/ultraplot/ultraplot/axes/plot.py", line 1811, in _fix_patch_edges
    for contour in obj.collections:
                   ^^^^^^^^^^^^^^^
AttributeError: 'QuadContourSet' object has no attribute 'collections'

It works with matplotlib==3.9.3. It looks like this collections attribute was removed in matplotlib version 3.8: https://matplotlib.org/stable/api/prev_api_changes/api_changes_3.8.0.html#contourset-is-now-a-single-collection.

Activity

  1. austin-hoover commented on Jan 10, 2025

    @austin-hoover
    Author
  2. added a commit that references this issue on Jan 10, 2025
    bc53d83
  3. thibaultDrt commented on Jan 11, 2025

    @thibaultDrt

    Tricontourf encounters a similar issue.

    This is working 👍

    fig, ax = uplot.subplot()
    ax.tricontourf(x, y, z, ec="none")

    This is not working 👎

    fig, ax = uplot.subplot()
    ax.tricontourf(x, y, z)
    ---------------------------------------------------------------------------
    AttributeError                            Traceback (most recent call last)
    Cell In[12], line 2
          [1] fig, ax = uplot.subplot()
    ----> [2] ax.tricontourf(x, y, z)
          [3] ax.triplot(x, y)
    
    File ~/.venv/lib/python3.11/site-packages/ultraplot/internals/inputs.py:327, in _preprocess_or_redirect.<locals>._decorator.<locals>._preprocess_or_redirect(self, *args, **kwargs)
        [325]     kwargs["color"] = color
        [326] # Call main function
    --> [327] return func(self, *args, **kwargs)
    
    File ~/.venv/lib/python3.11/site-packages/ultraplot/axes/plot.py:4446, in PlotAxes.tricontourf(self, x, y, z, **kwargs)
       [4444] m = cm = self._call_native("tricontourf", x, y, z, **kw)
       [4445] m._legend_label = label
    -> [4446] self._fix_patch_edges(m, **edgefix_kw, **contour_kw)  # no-op if not contour_kw
       [4447] if contour_kw or labels_kw:
       [4448]     cm = self._fix_contour_edges("tricontour", x, y, z, **kw, **contour_kw)
    
    File ~/.venv/lib/python3.11/site-packages/ultraplot/axes/plot.py:1811, in PlotAxes._fix_patch_edges(obj, edgefix, **kwargs)
       [1808] obj.set_linewidth(linewidth)
       [1809] obj.set_edgecolor("face")
    -> [1811] for contour in obj.collections:
       [1812]     contour.set_linestyle("-")
       [1813]     contour.set_linewidth(linewidth)
    
    AttributeError: 'TriContourSet' object has no attribute 'collections'
    
  4. cvanelteren commented on Jan 11, 2025

    @cvanelteren
    Collaborator

    We are currently not supporting 3.10. Having said that, the issue you raised was on my todo! I left some comments on the PR you raised. Thanks for the input :D!

  5. cvanelteren commented on Jan 11, 2025

    @cvanelteren
    Collaborator

    Fixed and merge in main. See the tag release page for the latest.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions