Skip to content

[BUG] - likelihood_plot raises AttributeError with matplotlib 3.10 ('QuadContourSet' has no attribute 'collections') #56

Description

@YasuakiH

Describe the bug
When I run likelihood_plot using the demo script from the documentation below, I encounter an error:

https://reliability.readthedocs.io/en/stable/Likelihood%20plot.html

Error message:

AttributeError: 'QuadContourSet' object has no attribute 'collections'

To Reproduce

from reliability.Reliability_testing import likelihood_plot
import matplotlib.pyplot as plt

old_design = [2, 9, 23, 38, 67, 2, 11, 28, 40, 76, 3, 17, 33, 45, 90, 4, 17, 34, 55, 115, 6, 19, 34, 56, 126, 9, 21, 37, 57, 197]
likelihood_plot(distribution="Weibull", failures=old_design, CI=[0.9, 0.95])
plt.show()

Expected behavior
The function should generate a likelihood plot without raising an exception, as shown in the documentation.

** Environment **

  • Python: 3.10.11
  • reliability: 0.9.0
  • matplotlib: 3.10.8
  • IPython: 8.39.0

** Full traceback **

Python 3.10.11 (tags/v3.10.11:7d4cc5a, Apr  5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.39.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import reliability

In [2]: reliability.__version__
Out[2]: '0.9.0'

In [3]: import matplotlib

In [4]: matplotlib.__version__
Out[4]: '3.10.8'

In [5]: from reliability.Reliability_testing import likelihood_plot
   ...: import matplotlib.pyplot as plt
   ...:
   ...: old_design = [2, 9, 23, 38, 67, 2, 11, 28, 40, 76, 3, 17, 33, 45, 90, 4, 17, 34, 55, 115, 6, 19, 34, 56, 126, 9, 21, 37, 57, 197]
   ...: likelihood_plot(distribution="Weibull", failures=old_design, CI=[0.9, 0.95])
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[5], line 5
      2 import matplotlib.pyplot as plt
      4 old_design = [2, 9, 23, 38, 67, 2, 11, 28, 40, 76, 3, 17, 33, 45, 90, 4, 17, 34, 55, 115, 6, 19, 34, 56, 126, 9, 21, 37, 57, 197]
----> 5 likelihood_plot(distribution="Weibull", failures=old_design, CI=[0.9, 0.95])

File H:\git\my-study\python\Python_Emacs_IDE\.env\lib\site-packages\reliability\Reliability_testing.py:1509, in likelihood_plot(distribution, failures, right_censored, CI, method, color)
   1505 plt.contourf(
   1506     X, Y, LLmesh, [LLcontour, LLmax], colors=color, alpha=0.5 / len(CI)
   1507 )
   1508 # get the plotting limits
-> 1509 v = contour.collections[0].get_paths()[0].vertices
   1510 xmin = min(xmin, min(v[:, 0]))
   1511 xmax = max(xmax, max(v[:, 0]))

AttributeError: 'QuadContourSet' object has no attribute 'collections'

Additional context
This issue occurs when using a recent version of matplotlib.
It may be related to a change in the QuadContourSet API:

matplotlib/matplotlib#29575

** Possible workaround **

As a temporary workaround, I modified the following line in Reliability_testing.py:

1509c1509,1510
<         v = contour.collections[0].get_paths()[0].vertices

---
>         # v = contour.collections[0].get_paths()[0].vertices

>         v = contour.get_paths()[0].vertices

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions