I’m working on a Windows computer through a local host. My Jupyter Notebook is not executing the script that I have presented it and it will not show the shapes and dimensions at all. It is as if the script is not there. Here is the script below. Could someone please help explain what I am doing wrong?
import matplotlib.pyplot as plt
%matplotlib inline
class Circle(object):
# Constructor
def __init__(self, radius=3, color='blue'):
self.radius = radius
self.color = color
# Method
def add_radius(self, r):
self.radius = self.radius + r
return(self.radius)
def drawCircle(self):
plt.gca().add_patch(plt.Circle((0, 0), radius=self.radius, fc=self.color))
plt.axis('scaled')
plt.show()
Is this all of your code? Did you make an error pasting it in?
First, as posted it has a syntax error in regards to the indentation.
Fixing that though still isn’t going to get you anywhere if that truly is the extent of your code. The initial two lines import matplotlib and set the style for displaying matplotlib objects. Then following that you have only defined a class and methods in your code.
You would need to invoke and use what you have set up. For example:
import matplotlib.pyplot as plt
%matplotlib inline
class Circle(object):
# Constructor
def __init__(self, radius=3, color='blue'):
self.radius = radius
self.color = color
# Method
def add_radius(self, r):
self.radius = self.radius + r
return(self.radius)
def drawCircle(self):
plt.gca().add_patch(plt.Circle((0, 0), radius=self.radius, fc=self.color))
plt.axis('scaled')
plt.show()
c1 = Circle() # make an instance of your class
c1.drawCircle() # invoke a method of that class
Result
Hello fomightez,
That works. Thank you so much for your help!
Regards