Python 在正方形中绘制正方形

Python 在正方形中绘制正方形,python,matplotlib,Python,Matplotlib,在正方形中绘制正方形时,只显示图形。我不知道,我的代码怎么了 在Pycharm中,我正在尝试绘制它 ''' ''if子句中的代码仅在x的第二个元素比第一个元素大1时执行。但是最初x=[0,0,…],所以第一个和第二个元素是相同的。因此,代码永远不会执行,因此不会显示正方形。是的……现在它可以工作了……感谢您找到错误 import matplotlib.pyplot as plt def square(x,y): if (x[1]-x[0]>=1): plt.plot(

在正方形中绘制正方形时,只显示图形。我不知道,我的代码怎么了

在Pycharm中,我正在尝试绘制它

'''


''

if子句中的代码仅在
x
的第二个元素比第一个元素大1时执行。但是最初
x=[0,0,…]
,所以第一个和第二个元素是相同的。因此,代码永远不会执行,因此不会显示正方形。是的……现在它可以工作了……感谢您找到错误
import matplotlib.pyplot as plt
def square(x,y):
    if (x[1]-x[0]>=1):
       plt.plot(x,y,'ro--')
       x=[x[0]+1,x[1]+1,x[2]-1,x[3]-1,x[0]+1]
       y=[y[0]+1,y[1]-1,y[2]-1,y[3]+1,y[0]+1]
       return square(x,y)
def PlotSquare(size):
    y=[0,size,size,0,0]
    x=[0,0,size,size,0]
    square(x,y)
    plt.title("square")
    plt.axis([min(x)-1,max(x)+1,min(y)-1,max(y)+1])
    plt.grid()
    plt.show()
def main():
   size=int(input("Enter the size of square:"))
   PlotSquare(size)
main()