如何在Matplotlib中调整网格大小?

时间:2018-08-30 14:28:27

标签: python-3.x matplotlib

我想设置一个半径为1且以原点为中心的圆的动画。我用Python绘制它。但是问题是当它绘制图形时,圆看起来像一个椭圆: My Output

我的代码:

import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np

fig = plt.figure()
ax = plt.axes(xlim=(-2,2), ylim=(-2, 2))
line, = ax.plot([], [], lw=2)

def init():
    # creating an empty plot/frame
    line.set_data([], [])
    return line,

plt.style.use('ggplot')
# lists to store x and y axis points
xdata, ydata = [], []

# animation function
def animate(i):
    # t is a parameter
    t = 0.1*i

    # x, y values to be plotted
    x = np.cos(t)
    y = np.sin(t)

    # appending new points to x, y axes points list
    xdata.append(x)
    ydata.append(y)

    # set/update the x and y axes data
    line.set_data(xdata, ydata)

    # return line object
    return line,

# setting a title for the plot
plt.title('$x^2+y^2=1$')
# hiding the axis details
#plt.axis('off')

# call the animator    
anim = animation.FuncAnimation(fig, animate, 
init_func=init,frames=100,interval=20, blit=True)

# save the animation as mp4 video file
anim.save('animated_coil.mp4', writer = 'ffmpeg', 
fps = 50,dpi=100)

# show the plot
plt.show()

有人可以帮我调整网格大小吗?

0 个答案:

没有答案