# C1\_W3\_Lab1 AttributeError: 'CheckButtons' object has no attribute 'rectangles'

**URL:** <https://community.deeplearning.ai/t/c1-w3-lab1-attributeerror-checkbuttons-object-has-no-attribute-rectangles/714843>\
**Category:** Supervised ML: Regression and Classification\
**Tags:** week-module-1\
**Created:** [October 27, 2024, 8:49pm UTC](https://community.deeplearning.ai/t/c1-w3-lab1-attributeerror-checkbuttons-object-has-no-attribute-rectangles/714843 "2024-10-27T20:49:45Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![gyorgy.zsuppan](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/gyorgy.zsuppan/32/98550_2.png) [@gyorgy.zsuppan](https://community.deeplearning.ai/u/gyorgy.zsuppan)\
**Post date:** [October 27, 2024, 8:49pm UTC](https://community.deeplearning.ai/t/c1-w3-lab1-attributeerror-checkbuttons-object-has-no-attribute-rectangles/714843/1 "2024-10-27T20:49:46Z")

</div>

Hi, when I try to run the Optional lab: **Sigmoid function and logistic regression** locally, I get an error: **AttributeError: ‘CheckButtons’ object has no attribute ‘rectangles’**

The issue in this piece of code:  
def resize\_sq(self, bcid):  
“”" resizes the check box “”"  
#future reference  
#print(f"width : {bcid.rectangles[0].get\_width()}“)  
#print(f"height : {bcid.rectangles[0].get\_height()}”)  
#print(f"xy : {bcid.rectangles[0].get\_xy()}“)  
#print(f"bb : {bcid.rectangles[0].get\_bbox()}”)  
#print(f"points : {bcid.rectangles[0].get\_bbox().get\_points()}") #[[xmin,ymin],[xmax,ymax]]

```
    h = bcid.rectangles[0].get_height()
    bcid.rectangles[0].set_height(3*h)

    ymax = bcid.rectangles[0].get_bbox().y1
    ymin = bcid.rectangles[0].get_bbox().y0

    bcid.lines[0][0].set_ydata([ymax,ymin])
    bcid.lines[0][1].set_ydata([ymin,ymax])

```

The matplotlib 3.9.2 version is installed. Any suggestions how to fix this?

---

<div class="post-metadata">

**Author:** ![nadtriana](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/nadtriana/32/167698_2.png) [@nadtriana](https://community.deeplearning.ai/u/nadtriana)\
**Post date:** [October 27, 2024, 10:08pm UTC](https://community.deeplearning.ai/t/c1-w3-lab1-attributeerror-checkbuttons-object-has-no-attribute-rectangles/714843/2 "2024-10-27T22:08:44Z")

</div>

Hi György, welcome to the community!

The error you’re experiencing is probably due to changes in the `matplotlib` library, where the `CheckButtons` object no longer includes the `rectangles` attribute as of version 3.9.2. If the functionality worked with a previous version, you could downgrade to an earlier version, such as `matplotlib==3.5.3`, where the `rectangles` attribute was accessible:

```python
pip install matplotlib==3.5.3

```

Hope this helps!

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [October 27, 2024, 11:43pm UTC](https://community.deeplearning.ai/t/c1-w3-lab1-attributeerror-checkbuttons-object-has-no-attribute-rectangles/714843/3 "2024-10-27T23:43:09Z")

</div>

Running a Coursera lab on any other platform always presents version compatibility problems.

---

<div class="post-metadata">

**Author:** ![gyorgy.zsuppan](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/gyorgy.zsuppan/32/98550_2.png) [@gyorgy.zsuppan](https://community.deeplearning.ai/u/gyorgy.zsuppan)\
**Post date:** [October 28, 2024, 4:50pm UTC](https://community.deeplearning.ai/t/c1-w3-lab1-attributeerror-checkbuttons-object-has-no-attribute-rectangles/714843/4 "2024-10-28T16:50:04Z")

</div>

Thank you nadtriana, for your response.

matplotlib3.5.3 is quite old one, I wonder if the newer library version supports alternative methods we can use here.

---

<div class="post-metadata">

**Author:** ![nadtriana](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/nadtriana/32/167698_2.png) [@nadtriana](https://community.deeplearning.ai/u/nadtriana)\
**Post date:** [October 29, 2024, 12:47pm UTC](https://community.deeplearning.ai/t/c1-w3-lab1-attributeerror-checkbuttons-object-has-no-attribute-rectangles/714843/5 "2024-10-29T12:47:40Z")

</div>

You’re right. You can try replacing `bcid.rectangles` with an alternative property if one exists, such as `bcid.ax` or another attribute that can handle button height settings:

```auto
h = bcid.ax.patches[0].get_height()
bcid.ax.patches[0].set_height(3 * h)

ymax = bcid.ax.patches[0].get_bbox().y1
ymin = bcid.ax.patches[0].get_bbox().y0

bcid.lines[0][0].set_ydata([ymax, ymin])
bcid.lines[0][1].set_ydata([ymin, ymax])

```

A workaround would be to find the correct button object properties by inspecting `bcid` with `print(dir(bcid))` and look for attributes such as `bcid.patch`, `bcid.labels`, or `bcid.lines`. This may reveal a new property or structure for interacting with checkbox elements.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![Kmewes](https://avatars.discourse-cdn.com/v4/letter/k/a88e57/32.png) [@Kmewes](https://community.deeplearning.ai/u/Kmewes)\
**Post date:** [October 29, 2024, 5:15pm UTC](https://community.deeplearning.ai/t/c1-w3-lab1-attributeerror-checkbuttons-object-has-no-attribute-rectangles/714843/6 "2024-10-29T17:15:54Z")

</div>

![IMG_0113](https://global.discourse-cdn.com/dlai/original/3X/8/6/8622b2e6b810205ba740d6afce527c045cda6177.jpeg)  
I’m getting this error on my last lab for Week three on exercise 3 and I don’t know what im doing wrong

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [October 29, 2024, 5:19pm UTC](https://community.deeplearning.ai/t/c1-w3-lab1-attributeerror-checkbuttons-object-has-no-attribute-rectangles/714843/7 "2024-10-29T17:19:36Z")

</div>

@Kmewes, your question doesn’t seem to fit the topic of this thread (about the “CheckButtons object”).

In this case it would be better if you started a new topic.  
= = = = =  
The error message says your dj\_dw values are not correct. Notice that you have three identical values. That’s never a good sign. So check your dj\_dw calculation.

If you have future issues with this, please start a new thread.

---

<div class="post-metadata">

**Author:** ![Alexandros7701](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/alexandros7701/32/3167_2.png) [@Alexandros7701](https://community.deeplearning.ai/u/Alexandros7701)\
**Post date:** [January 11, 2025, 6:57pm UTC](https://community.deeplearning.ai/t/c1-w3-lab1-attributeerror-checkbuttons-object-has-no-attribute-rectangles/714843/8 "2025-01-11T18:57:24Z")

</div>

> [@nadtriana](#):
>
> print(dir(bcid))

Hi nadtriana,  
I tested this code and doesn’t work  
Regards

---

<div class="post-metadata">

**Author:** ![nadtriana](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/nadtriana/32/167698_2.png) [@nadtriana](https://community.deeplearning.ai/u/nadtriana)\
**Post date:** [January 13, 2025, 11:28pm UTC](https://community.deeplearning.ai/t/c1-w3-lab1-attributeerror-checkbuttons-object-has-no-attribute-rectangles/714843/11 "2025-01-13T23:28:24Z")

</div>

Thank you for reporting this issue. I have removed my message to not show your root folder.

---

<div class="post-metadata">

**Author:** ![Alexandros7701](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/alexandros7701/32/3167_2.png) [@Alexandros7701](https://community.deeplearning.ai/u/Alexandros7701)\
**Post date:** [January 14, 2025, 8:46pm UTC](https://community.deeplearning.ai/t/c1-w3-lab1-attributeerror-checkbuttons-object-has-no-attribute-rectangles/714843/12 "2025-01-14T20:46:10Z")

</div>

Thanks

---

<div class="post-metadata">

**Author:** ![rodajc](https://avatars.discourse-cdn.com/v4/letter/r/ccd318/32.png) [@rodajc](https://community.deeplearning.ai/u/rodajc)\
**Post date:** [April 18, 2025, 11:53am UTC](https://community.deeplearning.ai/t/c1-w3-lab1-attributeerror-checkbuttons-object-has-no-attribute-rectangles/714843/13 "2025-04-18T11:53:38Z")

</div>

An easier solution that worked for me is to just comment out or remove the offending code as per your original post. CheckButtons no longer seems to require (or allow access to) the .rectangles and .lines attributes. See the release notes for API changes made in Matplotlib version 3.7.0 (cannot add link to post…)

---

<div class="post-metadata">

**Author:** ![x1smind](https://avatars.discourse-cdn.com/v4/letter/x/e8c25b/32.png) [@x1smind](https://community.deeplearning.ai/u/x1smind)\
**Post date:** [April 22, 2025, 9:54pm UTC](https://community.deeplearning.ai/t/c1-w3-lab1-attributeerror-checkbuttons-object-has-no-attribute-rectangles/714843/14 "2025-04-22T21:54:10Z")

</div>

Update the function “resize\_sq” in this file → plt\_one\_addpt\_onclick.py to:

```auto
def resize_sq(self, bcid):
        """ resizes the check box """

        _, h = bcid.canvas.get_width_height()
        bcid.canvas.height = 3*h

        ymax = bcid.ax.bbox.y1
        ymin = bcid.ax.bbox.y0

        bcid.ax.set_xbound([ymax,ymin])
        bcid.ax.set_ybound([ymin,ymax])

```

fixes the issue as of matplotlib==3.10.1

**You might need to perform the following for the new change to take effect:**

- reset browser cache, restart browser
- remove \_\_pycache\_\_ and .ipynb\_checkpoints folders created in your notebook folder
- re-run jupyter

---

<div class="post-metadata">

**Author:** ![suwro](https://avatars.discourse-cdn.com/v4/letter/s/f475e1/32.png) [@suwro](https://community.deeplearning.ai/u/suwro)\
**Post date:** [January 16, 2026, 2:29pm UTC](https://community.deeplearning.ai/t/c1-w3-lab1-attributeerror-checkbuttons-object-has-no-attribute-rectangles/714843/15 "2026-01-16T14:29:27Z")

</div>

if figure is not shown in the last paragraph - just add fig.show() at the end of function plt\_one\_addpt\_onclick:

```python
class plt_one_addpt_onclick:

    """ class to run one interactive plot """

    def __init__ (self, x, y, w, b, logistic=True):
    .....
    fig,ax = plt.subplots(1,1,figsize=(8,4))
    .....
    fig.show()

```
