C1_W3_Lab1 AttributeError: 'CheckButtons' object has no attribute 'rectangles'

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?

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:

pip install matplotlib==3.5.3

Hope this helps!

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

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.

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:

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!


I’m getting this error on my last lab for Week three on exercise 3 and I don’t know what im doing wrong

@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.

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

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

Thanks

1 Like