How to change this piece of code

  • This is the optional lab of sigmoid function. But on running this lab locally it gives error:

  • Error:


  • AttributeError Traceback (most recent call last)
    Cell In[3], line 2
    1 plt.close(‘all’)
    ----> 2 addpt = plt_one_addpt_onclick( x_train,y_train, w_in, b_in, logistic=True)

    File ~/ai-ml/Course/Supervised Machine Learning: Regression and Classification /week3/plt_one_addpt_onclick.py:66, in plt_one_addpt_onclick.init(self, x, y, w, b, logistic)
    64 self.bthresh = CheckButtons(axthresh, (‘Toggle 0.5 threshold (after regression)’,))
    65 self.bthresh.on_clicked(self.thresh)
    —> 66 self.resize_sq(self.bthresh)

    File ~/ai-ml/Course/Supervised Machine Learning: Regression and Classification /week3/plt_one_addpt_onclick.py:179, in plt_one_addpt_onclick.resize_sq(self, bcid)
    171 “”" resizes the check box “”"
    172 #future reference
    173 #print(f"width : {bcid.rectangles[0].get_width()}“)
    174 #print(f"height : {bcid.rectangles[0].get_height()}”)
    175 #print(f"xy : {bcid.rectangles[0].get_xy()}“)
    176 #print(f"bb : {bcid.rectangles[0].get_bbox()}”)
    177 #print(f"points : {bcid.rectangles[0].get_bbox().get_points()}") #[[xmin,ymin],[xmax,ymax]]
    → 179 h = bcid.rectangles[0].get_height()
    180 bcid.rectangles[0].set_height(3*h)
    182 ymax = bcid.rectangles[0].get_bbox().y1

    AttributeError: ‘CheckButtons’ object has no attribute ‘rectangles’

  • Mainly you can see the last line saying that “‘CheckButtons’ object has no attribute ‘rectangles’”, which occurs due to change in the versions of matplotlib. I don’t know how to change the code that is written in file “plt_one_addpt_onclick”. I have new version of matplotlib , to refactor code for that??

Much easier if you install an older version of of matplotlib.

Sure, but could you kindly explain what’s happening in this part of the code?

Sorry, I can’t, I don’t have any knowledge of how matplotlib works.

1 Like